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
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.