How do I override a xml value in xslt?

Here should go questions about transforming XML with XSLT and FOP.
Posts: 53

How do I override a xml value in xslt?

Thu Oct 09, 2014 4:24 pm

In short whenever my xml element has the following DC19DAKHN or DC19D0000 , in xslt output I want to override that value with MN019015J .

How do I do this in XSLT?

My XML Code

Code: Select all


My xslt output is

Code: Select all


I want this to look like this instead

Code: Select all


Do I use If Choose?
Posts: 2

Re: How do I override a xml value in xslt?

Sun Oct 12, 2014 5:53 pm

There are many ways in XSLT you can do this. My preference would be to use a modified identity template, where you match upon the text nodes and replace the values you want replaced.

Code: Select all

<!-- XSLT 3.0: copies everything, unless matched -->
<xsl:mode on-no-match="shallow-copy" />

<!-- only match text nodes, because that's what we want to change here -->
<xsl:template match="text()">
    <xsl:value-of select="replace(., 'DC19DAKHN|DC19D0000', 'MN019015J')" />

The above code works with any XSLT 3.0 processor, like Saxon or Exselt. If you can't use an XSLT 3.0 processor and are stuck with 2.0, replace the xsl:mode declaration with an identity template.

Abel Braaksma, a streaming XSLT 3.0 processor

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests