Yes, this works. In XSLT 2.0 you could write more concisely:
 
<xsl:template match="/root/service_discovery/ip">
  <ip v="{@v}">
    <xsl:variable name="portlist" select="tokenize(ports, ',')"/>
    <xsl:variable name="resultlist select="tokenize(results, ',')"/>
    <xsl:for-each select="1 to count($portlist)">
       <portresults p="{$portlist[current()]}" r="{$resultlist[current()]}"/>
    </xsl:for-each>
  </ip>
</xsl:template>
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Namrata Patel
Sent: 15 March 2005 19:12
To: saxon-help@lists.sourceforge.net
Subject: [saxon] RE: tokenize

Michael,

 

            Thanks for your quick reply. The reason I asked this was because I wanted to iterate through the nodes of two tokenize result node-sets and I was getting confused as to how would I write my xsl. I have come up with the following xsl which works ok. Does the xsl make sense to you or you would do it some other way?? I am very new to xsl ( 1 month ), which you can see from my xsl.

 

<xsl:template match="/root/service_discovery/ip">

        <iphostsunion>

        <xsl:variable name="row" select="." />

                 <xsl:text>&#xa;</xsl:text>

 

            <xsl:element name="ip">

 

            <xsl:attribute name="v"><xsl:value-of select="$row/@v"/></xsl:attribute>

 

            <xsl:variable name="portlist" select="saxon:tokenize($row/ports,',')"/>

            <xsl:variable name="resultlist" select="saxon:tokenize($row/results, ',')"/>

 

            <xsl:for-each select="$portlist">

                <xsl:element name="portresults">

                <xsl:variable name="count" select="position()" />

                <xsl:variable name="result" select="$resultlist[$count]"/>

                <xsl:attribute name="p"><xsl:value-of select="."/></xsl:attribute>

                <xsl:attribute name="r"><xsl:value-of select="$result/."/></xsl:attribute>               

                </xsl:element>

            </xsl:for-each>

      </xsl:element>

</xsl:template>

 

Thanks again for your quick response

Namrata