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)
-> + First time to Stylus Studio 20... (3)
-> + xsl:if test statement result t... (4)
-> + XSLT for dynamic target fields (4)
-> + Remove duplicates (2)
-> + XML-XSL grouping issue while d... (2)
-> + Two XML files. Two Tables. One... (3)
-> + Saxon 9.3 with XSLV (2)
-> - How do I remove the text strin... (1)
-> + Xpath of each element (3)
-> + Attributes - required vs optio... (2)
-> + XML schema to XML schema with ... (2)
-> + how to preserve the & in X... (2)
-> + how to use variables within (2)
-> + need help in XSLT programming (3)
-> + XSLT Mapper Option... Where i... (3)
-> - Selecting element based on att... (1)
-> + replace question (2)
-> - select other node based on one... (1)
-> - XSLT question... (1)
-> - Mapper and XSL (1)
-> - Copying XML as is with one cha... (1)
-> - Help with XSLT (1)
-> - XSL repeat the parent node for... (1)
-> - xls to xml (1)
-> - Stylus support non-backreferen... (1)
-> - Assigning records to existing ... (1)
-> + xsl:for-each and key() (2)
-> + tags containing a: (2)
-> - Create a namespace in output f... (1)
-> - XML Converters problem on UNIX (1)
-> - Copy XML Based on IF Condition... (1)
-> - csv counting dependencies (1)
-> + For extension function, could ... (2)
-> - XML XSLT Transformation (1)
-> + Transform XSD to another XSD (3)
-> - New to Stylus (1)
-> + my enterprise install doesn't ... (2)
-> - Replace line in XML (1)
-> - 5010 HIPAA - Example EDI files... (1)
-> - Display table in two columns f... (1)
-> + java.lang.RuntimeException (4)
-> + Select Value-Of Qualified Elem... (2)
-> + Validating different sets of r... (2)
-> + Passing complete source docume... (2)
-> - XSLT to sort XML per schema (1)
-> - XSL to select the group of row... (1)
-> + first ancestor of a type (2)
-> - Column Width Adjustment (1)
-> + XSLT breakpoint being ignored ... (6)
-> - Creating a tab delimited file (1)
-> - Invalid characters in xml (1)
-> + Creating XSLT File Based on XS... (2)
-> - Unable to filter InputStream f... (1)
-> + finding a list of values (7)
-> - TEMP directory question (1)
-> - [HELP] Template and namespace (1)
-> - The prefix "xsl" for element "... (1)
-> - Need help comparing dates in x... (1)
-> - trying to sort a list of artic... (1)
-> + Count unique values using XSLT (3)
-> + Dot "." vs. self::node() (2)
-> + Output from report and XSL do ... (2)
-> + XSL report (2)
-> + cannot see valid values in the... (2)
-> - sum function help (1)
-> + XSLT transformation problem (2)
-> + Flat To nested XML using Keys (3)
-> - XSLT Editor autocomplete funct... (1)
-> - Receiving an argument from a l... (1)
-> + Can't using the Xalan-J in Sty... (2)
-> + Need help testing to see if th... (2)
-> + Any good way to handle repeati... (2)
-> - Renaming child element name wh... (1)
-> + What to do to only how last 4 ... (2)
-> + Help to access an element with... (3)
-> - Multiplication for-each (1)
-> - XSL / X-Path query (1)
-> - Help in creating XSD (1)
-> + JAVASCRIPT Inside XSL (2)
-> + is at possible to create edita... (2)
-> + Grouping on Multiple Field (2)
-> + XSLT 1.0 Grouping Small change... (2)
-> + Revision bar based on the page... (2)
-> + xslt to rtf (2)
-> + XEP/FOP Error (3)
-> + XML to XML Transformation (3)
-> + This XSLT has stumped me.. (2)
-> + converting XML to EACOM format (2)
-> + Stylus with XSLT 1.0 + EXSLT T... (2)
-> + Xslt Mapper (2)
-> - xml to xsl (1)
-> - creating a website (1)
-> - XML to PDF using XML Publisher... (1)
-> - Replace nodes (1)
-> - New to XSLT, need help with a ... (1)
-> - Modify XSLT - Have List of Cha... (1)
-> - Replace nodes in one xml file ... (1)
-> - Alternate Row Colour (1)
-> - convert text to XML and then m... (1)
-> - CDATA to XML - work with trans... (1)
-- Previous [61-80] [81-100] [101-120] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
V NVSubject: xsl:if always returns true when false
Author: V NV
Date: 09 Dec 2005 05:45 AM

Hi,
The 'if' condition in the following piece of xsl doesn't seem to work. Through the debugger, I can see that "myId" is "id12" and "curId" is "id15", but still the control goes to execute "call-template copy-as-it-is".

I don't know what's going wrong here.

The requirement is: I want to copy the ProductRevision as it is, except that I want to copy only the first AssociatedDataset element to the copied file.
Also there could be more that one ProductRevision Element in the xml file.

Regards,
VnV

xml:
=======================================================================
<ProductRevision accessRefs="#id4" id="id2" masterRef="#id26" name="000171" revision="A" subType="ItemRevision">
<Description>000171</Description>
<ApplicationRef application="TcEng" label="gtDNYkST3dzudA" version="wRBNYkST3dzudA"></ApplicationRef>
<UserData id="id3">
<UserValue title="last_mod_date" value="2005-11-29T17:27:47"></UserValue>
<UserValue title="object_string" value="000171/A"></UserValue>
</UserData>
<AssociatedDataSet dataSetRef="#id11" id="id12" role="IMAN_specification"></AssociatedDataSet>
<AssociatedDataSet dataSetRef="#id14" id="id15" role="IMAN_specification"></AssociatedDataSet>
<AssociatedDataSet dataSetRef="#id17" id="id18" role="IMAN_specification"></AssociatedDataSet>
<AssociatedForm formRef="#id22" id="id24" role="IMAN_master_form_rev"></AssociatedForm>
<AssociatedForm formRef="#id22" id="id25" role="item_master_tag"></AssociatedForm>
</ProductRevision>
=======================================================================

<xsl:template name="writeAssociatedDataSet">
<xsl:variable name="curId" select="current()/@id"/>
<xsl:variable name="myId" select="/plm:PLMXML/plm:ProductRevision/plm:AssociatedDataSet/@id"/>
<xsl:if test="$curId=$myId">
<xsl:call-template name="copy-as-it-is"/>
</xsl:if>
</xsl:template>

Postnext
Minollo I.Subject: xsl:if always returns true when false
Author: Minollo I.
Date: 09 Dec 2005 08:11 AM
What you are describing doesn't seem possible; if $curId and $myId have different values, there is no doubt that...
<xsl:if test="$curId=$myId">
<xsl:call-template name="copy-as-it-is"/>
</xsl:if>
...should not call the copy-as-it-is template.

Feel free to attach or email me the whole XSLT and XML document you are using; I'll try to understand what's going on there.

Minollo

Postnext
V NVSubject: xsl:if always returns true when false
Author: V NV
Date: 11 Dec 2005 11:21 PM
Attached are the xml file and xslt file.


DocumentUntitled3.xsl
xsl file

Document000171_A.xml

Postnext
V NVSubject: xsl:if always returns true when false
Author: V NV
Date: 12 Dec 2005 05:02 AM
I just realised that I'm comparing two xsd:ID elements - Can't I use xsl:if or xsl:when to compare two xsd:ID elements?

Postnext
Minollo I.Subject: xsl:if always returns true when false
Author: Minollo I.
Date: 12 Dec 2005 08:56 AM
The problem in your <xsl:if> condition is that you are testing $Id, which contains one @id attribute, against $MId which contains a nodeset of 3 @id attributes. One of those 3 @id attributes match your single $Id @id attribute; you can see it if you expand the definition of the variable in the Variables window (the summary value displayed next to $MId can be mis-leading).

You'll need to change the part which assignes a value to $MId to make sure you select one specific id; maybe you want to change...
<xsl:variable name="myId" select="/plm:PLMXML/plm:ProductRevision/plm:AssociatedDataSet/@id"/>
...into...
<xsl:variable name="myId" select="@id"/>

Also, I noticed that your XSLT has a <xsl:template match="*"> inside which you do a choose based on the element name of the current node... That's skipping the whole template matching algorithm which is one of the strongest points in XSLT; a more XSLTish way to do things would be creating a matched template for each element/attribute that you want to deal with.

Hope this helps,
Minollo

Postnext
V NVSubject: xsl:if always returns true when false
Author: V NV
Date: 16 Dec 2005 03:57 AM
Thanks for your suggestion. I will try to replace the "match template=*". My problem is, I have a schema containing hundreds of elements, and the xml file does not necessarily contain all the elements. Thats why I designed the template I'm using.

Using your approach, for all elements, I have to explicity add all the attrs of each element.
For ex: I my example, I need to write all attrs of <dad>, <member> <child> and <details> explicitly. Can I write a template, like "copy-as-it-is", which will copy all attrs of the element, without explicitly writing down each of them?

If I use the folowing xsl file:
<PLMXML>
<Header>
<xsl:call-template name="copy-as-it-is" />
</Header>
<ProductRevision>
<xsl:call-template name="copy-as-it-is" />
<Description>
<xsl:call-template name="copy-as-it-is" />
</Description>
<ApplicationRef>
<xsl:call-template name="copy-as-it-is" />
</ApplicationRef>
<AssociatedDataSet>
<xsl:call-template name="copy-as-it-is" />
</AssociatedDataSet>
</ProductRevision>
<Product>
<xsl:call-template name="copy-as-it-is" />
<Description>
<xsl:call-template name="copy-as-it-is" />
</Description>
<ApplicationRef>
<xsl:call-template name="copy-as-it-is" />
</ApplicationRef>
</Product>
<AccessIntent>
<xsl:call-template name="copy-as-it-is" />
</AccessIntent>

<Site>
<xsl:call-template name="copy-as-it-is" />
</Site>

<DataSet>
<xsl:call-template name="copy-as-it-is" />
<ApplicationRef>
<xsl:call-template name="copy-as-it-is" />
</ApplicationRef>
</DataSet>

<ExternalFile>
<xsl:call-template name="copy-as-it-is" />
<ApplicationRef>
<xsl:call-template name="copy-as-it-is" />
</ApplicationRef>
</ExternalFile>
</PLMXML>
</xsl:template>
<xsl:template name="copy-as-it-is" >
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
, I get an error: "Output document cannot be parsed as xml: Expected element name". I see the output xml file as
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema">
<Header>
<#document/>
</Header>
<ProductRevision>
<#document/>
<Description>
<#document/>
</Description>
<ApplicationRef>
<#document/>
</ApplicationRef>
<AssociatedDataSet>
<#document/>
</AssociatedDataSet>
</ProductRevision>
<Product>
<#document/>
<Description>
<#document/>
</Description>
<ApplicationRef>
<#document/>
</ApplicationRef>
</Product>
<AccessIntent>
<#document/>
</AccessIntent>
<Site>
<#document/>
</Site>
<DataSet>
<#document/>
<ApplicationRef>
<#document/>
</ApplicationRef>
</DataSet>
<ExternalFile>
<#document/>
<ApplicationRef>
<#document/>
</ApplicationRef>
</ExternalFile>
</PLMXML>

which is wrong?
What is the problem with my template?
Regards,

Posttop
Minollo I.Subject: xsl:if always returns true when false
Author: Minollo I.
Date: 16 Dec 2005 09:34 AM
<xsl:copy-of> may help you (http://www.w3.org/TR/xslt).
If you are getting <#document> in your output, it means that you are invoking your "copy-as-it-is" template in the root context; you need to navigate down to what the correct source context is before using your copy-as-it-is template.

If you have general XSLT usage questions, that seems to me you have, I would suggest that you use the xsl-list at http://www.mulberrytech.com/xsl/xsl-list/index.html

Minollo

   
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.