XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Julio de la VegaSubject: Using Variables. How to use a flag to insert or not a label
Author: Julio de la Vega
Date: 15 Oct 2007 10:34 AM
Originally Posted: 15 Oct 2007 10:04 AM
Hi *,

I am trying to insert a specific label only once in my xml. Let me show you my scenario:

I have 3 types of nodes (node_1, node_2 and node_3). They can appear together or not but allways in the same order. Examples of the diferent secuences that can appear in my input data:

node_1, node_2 and node_3
node_1, node_2
node_1, node_3;
node_2 and node_3
node_1
node_2
node_3

I have to insert a tag but only in the first element of this secuence.
I thought to use a variable as a flag and "xsl:if" command to decide when to insert or not the tag but I can not use it because I can not update the variable with a new value as soon as I insert my first tag.

Could you please give me an overview about how I could manage this situation?

My initial idea and my actual development that do not work:


<xsl:variable name="INSERT_LABEL" select="'Y'"/>


<xsl:template match="node_1">
<NODE_1>
<xsl:if test="$ INSERT_LABEL ='Y' ">
<LABEL>S</LABEL>
<xsl:variable name=" INSERT_LABEL " select="'N'"/>
</xsl:if>
<xsl:copy-of select="*"/>
</NODE_1>
</xsl:template>

<xsl:template match="node_2">
<NODE_2>
<xsl:if test="$ INSERT_LABEL ='Y' ">
<LABEL>S</LABEL>
<xsl:variable name=" INSERT_LABEL " select="'N'"/>
</xsl:if>
<xsl:copy-of select="*"/>
</NODE_2>
</xsl:template>


Thanks in advance


Best Regard

Julio

Postnext
(Deleted User) Subject: Using Variables. How to use a flag to insert or not a label
Author: (Deleted User)
Date: 16 Oct 2007 11:27 AM
Hi Julio,
if the nodes are the only children of a node, you could use count(preceding-sibling::*)=0 to test if the current one is the first one.

Hope this helps,
Alberto

Postnext
Julio de la VegaSubject: Using Variables. How to use a flag to insert or not a label
Author: Julio de la Vega
Date: 16 Oct 2007 12:00 PM
Hi Alberto,

They are not the only children of a node :-(

Thank you

More ideas?

Posttop
(Deleted User) Subject: Using Variables. How to use a flag to insert or not a label
Author: (Deleted User)
Date: 22 Oct 2007 05:37 AM
Hi Julio,
you can try with count(preceding-sibling::*[starts-with(local-name(.),'node_')])=0

Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.