<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="key_sample.xsl" ?>
</document>
<test id="1" name="a">
<test id="2" name="b">
<test id="3" name="c">
<test id="4" name="d">
<data>
<item>
<id>1</id>
<value>value1</value>
<testid>1</testid>
</item>
<item>
<id>2</id>
<value>value2</value>
<testid>1</testid>
</item>
<item>
<id>3</id>
<value>value3</value>
<testid>3</testid>
</item>
<item>
<id>4</id>
<value>value4</value>
<testid>2</testid>
</item>
</data>
</document>
XSL 如下
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:key name="test-search" match="test" use="@id"/>
<xsl:template match="document">
<HTML>
<BODY>
<xsl:for-each select="data/item">
<div>
id=<xsl:value-of select="id" />
value=<xsl:value-of select="value" />
<xsl:for-each select="key('test-search', testid)">
test name=<xsl:value-of select="@name"/>
</xsl:for-each>
</div>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
<HTML>
<BODY>
<xsl:for-each select="data/item">
<div>
id=<xsl:value-of select="id" />
value=<xsl:value-of select="value" />
<xsl:for-each select="key('test-search', testid)">
test name=<xsl:value-of select="@name"/>
</xsl:for-each>
</div>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
id=1 value=value1 test name=a
id=2 value=value2 test name=a
id=3 value=value3 test name=c
id=4 value=value4 test name=b
沒有留言:
張貼留言