How do I override a xml value in xslt?
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 62
- Joined: Thu Jun 26, 2014 9:00 pm
How do I override a xml value in xslt?
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
My xslt output is
I want this to look like this instead
Do I use If Choose?
How do I do this in XSLT?
My XML Code
Code: Select all
<ValueID>
<MyID>[B]DC19DAKHN[/B]</MyID>
</ValueID>
My xslt output is
Code: Select all
<myID>[B]DC19D0000[/B]</myID>
Code: Select all
<myID>[B]MN019015J[/B]</myID>
Do I use If Choose?
-
- Posts: 2
- Joined: Sun Oct 12, 2014 5:34 pm
Re: How do I override a xml value in xslt?
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.
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.
HTH,
Abel Braaksma
http://Exselt.net, a streaming XSLT 3.0 processor
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')" />
</xsl:template>
HTH,
Abel Braaksma
http://Exselt.net, a streaming XSLT 3.0 processor
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service