get another sequence elements'value in one sequence.

Posted by lxusharp on Stack Overflow See other posts from Stack Overflow or by lxusharp
Published on 2010-04-13T16:48:44Z Indexed on 2010/04/13 16:53 UTC
Read the original article Hit count: 266

Filed under:

I have an XML file as below, and I want to transform it with xslt.

I want to achieve is: when do the for-each of "s1" elements, I want to get the corresponding "r1"'s "value" attbute value. the xslt I wrote as below, but it does not work, can anyone give a help? thanks.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="html" indent="yes"/>
    <xsl:template mode="getr1" match="summary" >
        <xsl:param name="index"/>
        <xsl:value-of select="r1[$index][@value]"/>
    </xsl:template>

    <xsl:template match="/">
        <html>
            <body>
                <ul>
                <xsl:for-each select="root/s1">
                    <xsl:variable name="i" select="position()"/>
                    <li>
                        <xsl:value-of select ="@name"/>
                        :
                        <!--<xsl:apply-templates mode="getr1" select="/root/summary">
                            <xsl:with-param name="index" select="$i" />
                        </xsl:apply-templates>-->
                        <!--I want to get the corresponding r1's value according to the index -->
                        <!-- but above code is not work.-->
                    </li>
                </xsl:for-each>
                </ul>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

© Stack Overflow or respective owner

Related posts about xslt