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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.