我需要保存節點并在 <xsl:call-template name="update.target"> 中傳遞此節點,我該怎么做?我在網上找了資料,沒找到
XML
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year lol="1">1985</year>
</cd>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<target>
<first>Jane</first>
<second>Lane</second>
</target>
</cd>
</catalog>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="catalog">
<xsl:if test="cd/target">
<xsl:call-template name="update.target">
<!-- pass <target> node in update.target template -- >
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="update.target">
... do something
</xsl:template>
</xsl:stylesheet>
我嘗試使用 xsl:param 和 xsl:with-param,但我不能。
uj5u.com熱心網友回復:
需要考慮不同的變化。
- 在模板output.target中引入param:
<xsl:template name="update.target">
<xsl:param name="target" />
- 將一些目標傳遞給 updated.target:
<xsl:if test="cd/target">
<xsl:call-template name="update.target">
<xsl:with-param name="target" select="cd/target"/>
- 要輸出傳遞的引數,可以使用 value-of:
<xsl:value-of select="$target/first/text()" />
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/535504.html
標籤:XMLxpathxslt
