0
我有一個xsl:模板,它有兩種風格,具體取決於屬性中的值。我需要多次調用此模板,每次都使用不同的標籤進行過濾。如何調用具有多個條件的xsl:apply-templates
我有下面的XML:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<item name="Recommendations">
<richtext>
<pardef/>
<par><run>This is the </run><run>preamble.</run></par>
<pardef list='bullet'/>
<par><run>This is the </run><run>first bullet.</run></par>
<par><run>This is the second </run><run>bullet.</run></par>
</richtext>
</item>
<item name="Comments">
<richtext>
<pardef/>
<par><run>This is the </run><run>preamble.</run></par>
<pardef list='bullet'/>
<par><run>This is the </run><run>first bullet.</run></par>
<par><run>This is the second </run><run>bullet.</run></par>
</richtext>
</item>
</document>
多虧了@ UL1發佈here的解決方案,我有以下XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/>
<xsl:key name="key-for-par" match="document/item/richtext/par" use="generate-id(preceding-sibling::pardef[1])"/>
<xsl:template match="/">
<html>
<body>
<table>
<tr>
<td>Recommendations</td>
<td>
<xsl:apply-templates select="pardef[@list = 'bullet']"/>
<xsl:apply-templates select="pardef[not(@list)]"/>
</td>
</tr>
<tr>
<td>Comments</td>
<td>
<xsl:apply-templates select="pardef[@list = 'bullet']"/>
<xsl:apply-templates select="pardef[not(@list)]"/>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="pardef[@list = 'bullet']">
<ul>
<xsl:for-each select="key('key-for-par', generate-id(.))">
<li>
<xsl:value-of select="run" separator=""/>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="pardef[not(@list)]">
<p>
<xsl:for-each select="key('key-for-par', generate-id(.))">
<xsl:value-of select="run" separator=""/>
</xsl:for-each>
</p>
</xsl:template>
</xsl:stylesheet>
非常感謝:) – b00kgrrl