You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by John Ollier <jo...@capula.co.uk> on 2002/12/13 17:58:30 UTC
Node as argument in "setParameter" method?
I have a simple stylesheet (shown below) which combines two XML
Documents effectively copying one into the other.
In my code this works:
transformer.setParameter("infoTextFile", "infoText.xml" )
Where "infoText.xml" is the name of a file containing the second document.
I want to do the same thing, but instead of "infoText.xml", I want to
pass as the parameter something that I can derive from a Node object
representing the same Document. My XSL book says the "document()"
function can take a URL as argument. Can I construct a URL which will
have the desired effect?
Thanks in advance.
John
<!-- imports info text into master document -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="infoTextFile"/>
<xsl:template match="/ | * | @* ">
<xsl:copy>
<xsl:apply-templates select=" * | @* | text()"/>
</xsl:copy>
</xsl:template>
<!-- copy everything except the 'info' -->
<xsl:template match="info">
<xsl:variable name="id">
<xsl:value-of select="parent::node/@id"/>
</xsl:variable>
<info>
<xsl:call-template name="insertInfoText">
<xsl:with-param name="id" select="$id"/>
<xsl:with-param name="document" select="."/>
</xsl:call-template>
</info>
</xsl:template>
<!-- info text is imported from the corresponding info text file -->
<xsl:template name="insertInfoText">
<xsl:param name="id"/>
<xsl:param name="document"/>
<xsl:variable name="infoText" select="document( $infoTextFile,
$document )/boilerplate/info[@id=$id]"/>
<xsl:copy-of select="$infoText/infoGroup"/>
</xsl:template>
</xsl:stylesheet>