|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Parsing copy-of result tree fragment
Mike Mahoney wrote:
> How does someone take a tree fragment from a copy-of and then turn
> around and use the results and parse out/replace certain characters.
You don't. Once you have used xsl:copy-of, you have put a copy of a branch
of the source tree into the result tree. You never had the opportunity to
change anything before it went into the result tree.
With pure XSLT 1.0, the solution involves using xsl:copy. xsl:copy works
like xsl:copy-of, but only copies the current node. The contents of the
xsl:copy element are used to generate the rest of the descendants of the
copied node.
> If the original xml were
> <object>
> <data1>
> <sub-data>
> joe's data
> </sub-data>
> </data1>
> </object>
>
> and the resulting fragment from the copy-of was
> <sub-data>
> joe's data
> </sub-data>
>
> I'd want the final output to be
> <sub-data>
> joe\'s data
> </sub-data>
<xsl:template match="sub-data">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="copying"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" mode="copying">
<xsl:call-template name="SubStringReplace">
<xsl:with-param name="stringIn" select="."/>
<xsl:with-param name="substringIn">'</xsl:with-param>
<xsl:with-param name="substringOut">\'</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="SubstringReplace">
<xsl:param name="stringIn"/>
<xsl:param name="substringIn"/>
<xsl:param name="substringOut"/>
<xsl:choose>
<xsl:when test="contains($stringIn,$substringIn)">
<xsl:value-of select="concat(substring-before($stringIn,$substringIn),$substringOut)"/>
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn" select="substring-after($stringIn,$substringIn)"/>
<xsl:with-param name="substringIn" select="$substringIn"/>
<xsl:with-param name="substringOut" select="$substringOut"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$stringIn"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- Mike
____________________________________________________________________
Mike J. Brown, software engineer at My XML/XSL resources:
webb.net in Denver, Colorado, USA http://skew.org/xml/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








