K
kurt hansen
hi
I thought that this would be easy, but maybe not so much.
I want to:
pass an xpath expression and a string value to a stylesheet
and
copy the source xml document, changing the value of the node described
by the xpath expression, to the new value.
It seems like it should look something like:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xslaram name="xpath-string"/>
<xslaram name="new-value"/>
<xsl:template match="/|*">
<xsl:copy>
<xsl:choose>
<xsl:when test="is current node the desired node?">
<xsl:call-template name="update-selected-node"/>
</xsl:when>
<xsltherwise>
<xsl:apply-templates select="@*|node()"/>
</xsltherwise>
<xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>
<xsl:template name="update-selected-node">
<xsl:value-of select="new-value"/>
</xsl:template>
</xsl:stylesheet>
How do you select or test for the node specified by $xpath-string?
Can you put the $xpath-string into a xsl:template match attribute?
thanks.
I thought that this would be easy, but maybe not so much.
I want to:
pass an xpath expression and a string value to a stylesheet
and
copy the source xml document, changing the value of the node described
by the xpath expression, to the new value.
It seems like it should look something like:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xslaram name="xpath-string"/>
<xslaram name="new-value"/>
<xsl:template match="/|*">
<xsl:copy>
<xsl:choose>
<xsl:when test="is current node the desired node?">
<xsl:call-template name="update-selected-node"/>
</xsl:when>
<xsltherwise>
<xsl:apply-templates select="@*|node()"/>
</xsltherwise>
<xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>
<xsl:template name="update-selected-node">
<xsl:value-of select="new-value"/>
</xsl:template>
</xsl:stylesheet>
How do you select or test for the node specified by $xpath-string?
Can you put the $xpath-string into a xsl:template match attribute?
thanks.