Hi Markus,
Actually I do want to modify parts.
Given following (a bit more complete now) xml
<aggregate>
<request>
<parameter name="placeholder1">textvalue</parameter>
<parameter name="placeholder2">anothertextvalue</parameter>
</request>
<content>
<url src="http://myurl?text=placeholder1"/>
<url src=http://myurl?text=placeholder2"/>
</content>
</aggregate>
I would like to
- extract the content tree
- for each of the parameter name attributes in the request tree I want to
search the content tree and replace all occurrences of this parameter name
attribute with the parameter value attribute
I think I'm close to the solution though
<xsl:template match="/" >
<xsl:apply-templates select="aggregate/content"/>
</xsl:template>
<xsl:template match="aggregate/content//@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- match all attribute values -->
<xsl:template match="aggregate/content//@*">
<xsl:comment><xsl:value-of select="."/></xsl:comment>
<xsl:attribute name="{name()}">
<!-- now here I need to loop over the parameter name attributes and search
each attribute, possibly *slow* -->
<xsl:call-template name="substring-replace">
<xsl:with-param name="search-for" select=""/>
<xsl:with-param name="replace-with" select="blah"/>
<xsl:with-param name="input" select="."/>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template name="substring-replace">
<xsl:param name="input"/>
<xsl:param name="search-for"/>
<xsl:param name="replace-with"/>
<xsl:comment><xsl:value-of select="$input"/><xsl:value-of
select="$search-for"/><xsl:value-of select="$replace-with"/></xsl:comment>
<xsl:choose>
<!-- empty search string produces infinite loop -->
<xsl:when test="$search-for=''">
<xsl:value-of select="$input"/>
</xsl:when>
<xsl:when test="contains($input, $search-for)">
<xsl:value-of select="substring-before($input, $search-for)"/>
<xsl:value-of select="$replace-with"/>
<xsl:call-template name="substring-replace">
<xsl:with-param name="input"
select="substring-after($input,$search-for)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: Markus Abt [mailto:abt(_at_)comet(_dot_)de]
Sent: Mittwoch, 6. August 2003 17:19
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: AW: [xsl] selecting everything below a node
Hi Jorg,
if you don't want to modify parts of it, you can use:
<xsl:copy-of select="/aggregate/content"/>
Adjust the xpath to your needs.
If you want to modify some nodes, use the identity transformation:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
Then use specific templates to do the modifications.
Regards,
Markus
__________________________
Markus Abt
Comet Computer GmbH
http://www.comet.de
----------
Von: Jorg Heymans
Gesendet: Mittwoch, 6. August 2003 16:43
An: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Betreff: [xsl] selecting everything below a node
Hi list,
Given following xml
<aggregate>
<request>
many children here
</request>
<content>
..many children here
</content>
</aggregate>
How do I extract the whole <content> tree (nodes + attributes) into a
different document?
Regards
Jorg
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list