Re: [xsl] Adding element to xml snippet using xslt

Subject: Re: [xsl] Adding element to xml snippet using xslt
From: Nishi Bhonsle <nishi.bhonsle@xxxxxxxxxx>
Date: Tue, 22 Feb 2005 16:25:56 -0800
David Carlisle wrote:

I was able to tackle the 'drillOutDir' node in the following way --
<xsl:template match="abc:configuration">
<xsl:element name="drillOutDir">
<xsl:value-of select="abc:configuration/drillOutDir"/>
</xsl:element> </xsl:template>

This results in the correct output xml doc ie

so you have abc:configuration elements that are children of
abc:configuration elements?

This results in the correct output xml doc ie <abc:configuration> <drillOutDir></drillOutDir> </abc:configuration>

do you really want emoty drilloutdir element here, or is that just empty
as the answer to the above question is no, in which case
     <xsl:value-of select="abc:configuration/drillOutDir"/>
will never generate ay text.

Now the only issue remaining is for the 'started' element node, which is at the same level as the 'drillOutDir' node but apparently needs to be merged using xslt.

I have no idea what you mean by that.

ie I can insert the following in the above template
<xsl:element name="started">
<xsl:attribute name="status"><xsl:text>true</xsl:text></xsl:attribute>

You could insert <started status="true"/>
which is equivalent but easier to type.

But I do not want to hardcode the value of the attribute status in my xslt. I would like to get it using the value of or something expression. Apparently when I use the value-of or any other copy-of select clause, I only get an empty 'started' node.
<xsl:copy-of select="@status[. = 'true' ]"/>
<xsl:value-of select="abc:configuration/started"/>
How can I resolve this part?

The xpath has to match your input.

     <xsl:copy-of select="@status[. = 'true' ]"/>
I don't know what you want this to do, but it just copies an attribute
node if it is of the form status="true" so it is more or less the same
as just hard coding that attribute into the template. (except it does
nothing if the attribute isn't in the source)

     <xsl:value-of select="abc:configuration/started"/>
If you are putting this in the template matching  abc:configuration
then your current node is abc:configuration so unless that element has a
child of the same name, this will select nothing (which is the same
question as I asked at the start). If started is a child of the current
node you want
     <xsl:value-of select="started"/>
if you just want the text or

     <xsl:copy-of select="started"/>
if you want a copy of the element.


<xsl:copy-of select="started"/>

copies the element correctly from the input source doc. Thanks a lot. Now, I get
<started status = "true></started>
Is there a way I can insert text for this 'started' element in the same template that does

<xsl:copy-of select="started"/>

to get
<started status = "true>This application was stopped.</started>


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread