I need save node and pass this node in <xsl:call-template name="update.target">, how i can do this ? I searched for information on the Internet, I could not find
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>
I try use xsl:param and xsl:with-param, but I could not.
CodePudding user response:
There are different changes to be considered.
- Introduce param to the template output.target:
<xsl:template name="update.target">
<xsl:param name="target" />
- Pass some target to updated.target:
<xsl:if test="cd/target">
<xsl:call-template name="update.target">
<xsl:with-param name="target" select="cd/target"/>
- To output the passed param, you can use value-of:
<xsl:value-of select="$target/first/text()" />