You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Volker Witzel <vo...@schenker.com> on 2001/12/06 08:49:12 UTC

create temporary node set

Hi *.

I ran into a problem and couldn't find help in my books.

I have two XML fragments:
<Type associated_key="land" key="dangerous">Dangerous goods</Type>
<Type associated_key="land" key="others">Other special goods</Type>
<Type associated_key="air" key="animals">Live animals</Type>
<Type associated_key="air" key="dangerous">Dangerous goods</Type>
<Type associated_key="air" key="others">Other special goods</Type>
<Type associated_key="air" key="unaccompanied">Unaccompanied baggage</Type>
<Type associated_key="air" key="valuable">Valuable cargo</Type>
<Type associated_key="sea" key="dangerous">Dangerous goods</Type>
<Type associated_key="sea" key="others">Other special goods</Type>
<Type associated_key="sea" key="oversized">Oversized cargo</Type>
<Type associated_key="sea" key="removal">Removal goods</Type>

the associated key is there to group valid entrys for air|land|sea

As the keys must not be printed out in alphabetical order, I have 
another fragment containing the ordering info:

<OrderingType key="07">others</OrderingType>
<OrderingType key="06">oversized</OrderingType>
<OrderingType key="05">removal</OrderingType>
<OrderingType key="04">unaccompanied</OrderingType>
<OrderingType key="03">animals</OrderingType>
<OrderingType key="02">valuable</OrderingType>
<OrderingType key="01">dangerous</OrderingType>

All my previous attempts to process these two fragments failed, as 
xsl:variables are not real variables. Now I think the best way is to 
generate a temporary xml node set containing the needed information:

<TmpType idx="01" key="dangerous">Dangerous goods</TmpType>
<TmpType idx="07" key="others">Other special goods</TmpType>
<TmpType idx="06" key="oversized">Oversized cargo</TmpType>
<TmpType idx="05" key="removal">Removal goods</TmpType>

I tried to generate this nodeset with xsl:element but I do not know if 
it worked as I'm unable to access it afterwards.

<xsl:template name="generateNodeSet">
<xsl:variable name="typeList" select="/output/lists/Type[@associated_key 
= 'sea']"/>
<xsl:for-each select="/output/lists/OrderingType">
     <xsl:sort select="@key"/>
     <xsl:variable name="idx" select="position"/>
     <xsl:variable name="key" select="."/>
     <xsl:variable name="value" select="$typeList[@key = $key]"/>
     <xsl:if test="$value">
         <xsl:element name="TmpType">
             <xsl:value-of select="$value"/>
         </xsl:element>
     </xsl:if>
</xsl:for-each>
</xsl:template>

I'm using Xalan & Xeerces 1.2.2.


Thanks very much in advance
Volker.