xsl copy xml but move 1 field value to another
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Mon Jun 25, 2007 3:38 pm
xsl copy xml but move 1 field value to another
Post by eakinpeter »
Hi guys
I am new to xsl and have what could be quite a simple problem. I am
trying to take an xml file and copy the entire file, i then want to
take a value out of 1 area in the file and put it in another area so
below is an example of what i'm trying to do:
Go from this xml
<startrequest>
<userdetails>
<username>
test username
</username>
<userdetails>
<furtherdetails>
.....................
.....................
</furtherdetails>
<requestdetails>
<username>
</username
</requestdetails>
</startrequest>
to this xml, notice i have moved the username from the userdetails tag
to the requestdetails tag, I am not aware of the structure of the xml
at runtime, all i know is that the requestdetails tag will be present
and the userdetails tag will be present but everything else can
change..
<startrequest>
<userdetails>
<username>
</username>
<userdetails>
<furtherdetails>
.....................
.....................
</furtherdetails>
<requestdetails>
<username>
test username
</username
</requestdetails>
</startrequest>
Can anyone help me with this, is someone able to provide me with the
xsl needed?
Thanks
Peter
I am new to xsl and have what could be quite a simple problem. I am
trying to take an xml file and copy the entire file, i then want to
take a value out of 1 area in the file and put it in another area so
below is an example of what i'm trying to do:
Go from this xml
<startrequest>
<userdetails>
<username>
test username
</username>
<userdetails>
<furtherdetails>
.....................
.....................
</furtherdetails>
<requestdetails>
<username>
</username
</requestdetails>
</startrequest>
to this xml, notice i have moved the username from the userdetails tag
to the requestdetails tag, I am not aware of the structure of the xml
at runtime, all i know is that the requestdetails tag will be present
and the userdetails tag will be present but everything else can
change..
<startrequest>
<userdetails>
<username>
</username>
<userdetails>
<furtherdetails>
.....................
.....................
</furtherdetails>
<requestdetails>
<username>
test username
</username
</requestdetails>
</startrequest>
Can anyone help me with this, is someone able to provide me with the
xsl needed?
Thanks
Peter
-
- Posts: 89
- Joined: Mon Mar 06, 2006 10:13 pm
You can create 2 templates for the specified username nodes like so:
<xsl:template match="userdetails/username">
<xsl:copy/> <!-- remove inside text -->
</xsl:template>
<xsl:template match="requestdetails/username">
<xsl:copy>
<xsl:value-of select="//userdetails/username"/> <!-- grab the new value -->
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="userdetails/username">
<xsl:copy/> <!-- remove inside text -->
</xsl:template>
<xsl:template match="requestdetails/username">
<xsl:copy>
<xsl:value-of select="//userdetails/username"/> <!-- grab the new value -->
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
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