Replacing parts of xml with xslt

C

C Gillespie

Dear All,

I hopefully have a simple problem.

I have a xml file, say

<AAA>
<BBB>test 1</BBB>
<BBB>test 2</BBB>
<CCC />
</AAA>

What I want to be able to do is pass an xpath reference with a substitute
string.
For example /AAA/BBB[1] & <DDD>new test</DDD>, would give

<AAA>
<DDD>new test</DDD>
<BBB>test 2</BBB>
<CCC />
</AAA>

Any help is appreciated.

Thanks
Colin
 
R

Robin Johnson

I have a xml file, say

<AAA>
<BBB>test 1</BBB>
<BBB>test 2</BBB>
<CCC />
</AAA>

What I want to be able to do is pass an xpath reference with a substitute
string.

<xsl:template match="/">
<xsl:apply-templates select="*" mode="copy"/>
</xsl:template>

<!-- these aren't the elements you're looking for... -->
<xsl:template mode="copy" match="*"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="text()|*" mode="copy"/>
</xsl:copy>
</xsl:template>

<!-- special templates like this 'catch' the data you're after -->
<xsl:template mode="copy" match="AAA/BBB[1]">
<DDD>New text</DDD>
</xsl:template>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top