inserting a new attribute to an existing element
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 8
- Joined: Tue Feb 15, 2005 12:00 am
inserting a new attribute to an existing element
Hi,
I have an xml file , which has several elements ..i would like to add a new attribute to an existing element.
eg. if i wan to add attribute "district" to element "Center"
<xsl:attribute name"District">45</xsl:attribute>
and write the xml file again with updated attribute.
Thanks
I have an xml file , which has several elements ..i would like to add a new attribute to an existing element.
eg. if i wan to add attribute "district" to element "Center"
<xsl:attribute name"District">45</xsl:attribute>
and write the xml file again with updated attribute.
Thanks
Code: Select all
<Dispatch Data="16" Ver="1.5">
<Center No="2124" cc="US" region="35" Code="1" numBreaks="0" ShipNum="" GMT="0"/>
<DispDetails SerialNumber="8SZVB221" totalPkgs="5" >
<CurrencyID>L1379229754</CurrencyID>
</DispDetails>
</Dispatch>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
You can do that with something like:
Best Regards,
George
You can do that with something like:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Center">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="District">45</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
George
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