This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xsl for adding a tag

 
S Mithal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an xml document. I want to write an xsl to add a tag to the xml doc to add a tag as:

OLD FILE :
----------
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
.
.
.
</catalog>

NEW FILE:
---------

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<newtag>myTag</newtag>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
.
.
.
</catalog>

TIA
 
S Mithal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the same lines, I have a SOAP message to which I want to add a tag.
However, the message is output as is without the tag.

Here is the xsl:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput method="xml" />
<xsl:template match="/">
<xsl:copy-of select="." />
</xsl:template>
<xsl:template match="po">
<xsl:copy>
<Id>a new id</Id>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>


This is the message:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
</wsse:Security>
<Action>transfer</Action>
</soapenv:Header>
<soapenv:Body>
<ns1 oSubmit
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="urn o-submit">
<po xsi:type="xsd:string">
<PORequest>
<testNum>3</testNum>
<priceList>953</priceList>
<quantity>1</quantity>
<PONumber></PONumber>
<CreditCardNos>4178908723456781</CreditCardNos>
<Amount>56091.23</Amount>
<RequestedShipDate>020606</RequestedShipDate>
</PORequest>
</po>
</ns1 oSubmit>
</soapenv:Body>
</soapenv:Envelope>

Requirement is the below to add a tag called Id:


<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
</wsse:Security>
<Action>transfer</Action>
</soapenv:Header>
<soapenv:Body>
<ns1 oSubmit
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="urn o-submit">
<po xsi:type="xsd:string">
<Id>a new id</Id>
<PORequest>
<testNum>3</testNum>
<priceList>953</priceList>
<quantity>1</quantity>
<PONumber></PONumber>
<CreditCardNos>4178908723456781</CreditCardNos>
<Amount>56091.23</Amount>
<RequestedShipDate>020606</RequestedShipDate>
</PORequest>
</po>
</ns1 oSubmit>
</soapenv:Body>
</soapenv:Envelope>

Thanks
 
Abhiranjan Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...
use the following tag inside the xsl file where you are writing the match for the "catalog" element...

<xsl:element name="newTag">myTag</xsl:element>

this must create the element..hope this works...ciao
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic