• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Adding a new element to xml using xslt

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:
I have the following xml snippet --
<abc:configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://oracle.com/xmlns/abcst/configuration configuration.xsd" locale="en" webcache="false" rmi="true">
<started status="true"></started>
<server></server>
..
....
</abc:configuration>

I need to convert this to the following xml:
<abc:configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://oracle.com/xmlns/abcst/configuration configuration.xsd" webcache="false" useMgmt="true" metadata="true">

<drillOutDir></drillOutDir>
<started status="true"></started>
<server></server>
.....
</abc:configuration>

I have the following xsl, that converts the initial snippet to the resultant but i observed that the <started> element occurs before the <drillOutDir> element. How can I change my xsl to achieve the above xml in the exact order?

<xsl:template match="abc:configuration">
<xsl:copy>
<xsl:copy-of select="@*[local-name() != 'rmi' and local-name() != 'locale']"/>
<xsl:attribute name="useMgmt">
<xsl:text>true</xsl:text></xsl:attribute>
<xsl:attribute name="metadata"><xsl:text>true</xsl:text></xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
<xsl:text></xsl:text>
</xsl:template>

<xsl:template match="server">
<xsl:element name="drillOutDir">
</xsl:element>
</xsl:template>

Please help.
Thanks.
 
N Bhonsle
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have come to a point using the xslt in which I can get the "order" of the nodes preserved ie the "started" element occurs before the "drillOutDir" element but the attributes nodes for the started element are not preserved. Its skipped.
The current xslt looks like --

<xsl:template match="abc:configuration">
<xsl:copy>
<xsl:copy-of select="@*[local-name() != 'rmi' and local-name() != 'locale']"/>
<xsl:attribute name="useMgmt">
<xsl:text>true</xsl:text></xsl:attribute>
<xsl:attribute name="metadata"><xsl:text>true</xsl:text></xsl:attribute>
<xsl:apply-templates>
<xsl:sort select="boolean(self::server)" order="descending"/>
</xsl:apply-templates>
</xsl:copy>
<xsl:text></xsl:text>
</xsl:template>

<xsl:template match="server">
<xsl:element name="drillOutDir">
<xsl:value-of select="abc:configuration/drillOutDir"/>
</xsl:element>
<xsl:element name="started">
<xsl:copy-of select="@status[. = 'true' ]"/>
<xsl:value-of select="../abc:configuration/started"/>
</xsl:element>
</xsl:template>

<xsl:template match="abc:configuration/started">
<xsl:apply-templates/>
</xsl:template>

If I change this xslt to remove the started element from the server node and have a tranform for it separately then I do not even get the started node in the output xml.

What changes can I do to the above xslt in order to get
started node as in
<started status ="true"></started>
instead of what I m getting now ie
<started></started>

Thanks much.
[ February 21, 2005: Message edited by: N Bhonsle ]
 
N Bhonsle
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is resolved.

Thanks.
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic