[XSL] add attribute into existing XML

add attribute into existing XML [XSL] - XML/XSL - Programmation

Marsh Posté le 30-03-2005 à 08:42:53    

voici mon  autre  probleme
 
I need to add the attribute "version" in the wap-provisioningdoc node. How can I do this using the following XSL? This XSL gets rid of the node characteristic of type SETTINGSET.
 
current XSL
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl  utput method="xml" indent="yes"/>
 
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()[not(@type='SETTINGSET')]"/>
</xsl:copy>
</xsl:template>
 
</xsl:stylesheet>
 
 
 
Input XML
<wap-provisioningdoc>
<characteristic type="SETTINGSET">
<parm name="NAME" value="NOKIA-6170"/>
<parm name="STATE" value="2"/>
<parm name="SERVICE" value="WAPGPRS"/>
</characteristic>
<characteristic type="PXLOGICAL">
<parm name="TRUST"/>
<parm name="MASTER"/>
<parm name="STARTPAGE" value="http://www.bank.com/startpage.wml"/>
</characteristic>
<characteristic type="NAPDEF1">
<parm name="INTERNET"/>
</characteristic>
<characteristic type="APPLICATION">
<characteristic type="RESOURCE">
<parm name="STARTPAGE"/>
</characteristic>
</characteristic>
<characteristic type="ACCESS">
<parm name="RULE"/>
</characteristic>
</wap-provisioningdoc>
 
 
Result expected:
<wap-provisioningdoc version="1.0">
<characteristic type="PXLOGICAL">
<parm name="TRUST"/>
<parm name="MASTER"/>
<parm name="STARTPAGE" value="http://www.bank.com/startpage.wml"/>
</characteristic>
<characteristic type="NAPDEF1">
<parm name="INTERNET"/>
</characteristic>
<characteristic type="APPLICATION">
<characteristic type="RESOURCE">
<parm name="STARTPAGE"/>
</characteristic>
</characteristic>
<characteristic type="ACCESS">
<parm name="RULE"/>
</characteristic>
</wap-provisioningdoc>
 
 
Thanks

Reply

Marsh Posté le 30-03-2005 à 08:42:53   

Reply

Marsh Posté le 04-04-2005 à 15:51:17    

Code :
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3.   <xsl:output method="xml" indent="yes"/>
  4.   <xsl:template match="@*|node()">
  5.     <xsl:copy>
  6.       <xsl:if test="name()='wap-provisioningdoc'">
  7.           <xsl:attribute name="version">1</xsl:attribute>
  8.       </xsl:if>
  9.       <xsl:apply-templates select="@*|node()[not(@type='SETTINGSET')]"/>
  10.     </xsl:copy>
  11.   </xsl:template>
  12. </xsl:stylesheet>
  13. <!-- eof -->


 
testé avec MSXML 4 :jap:

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed