Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2004, 02:17 PM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default break a for loop

for loop through each record in the list_1
   for loop through each record in the list_2
      if list_1:Id = list_2:Id
         output the record of list_2

      else if list_1:Id cannot be FOUND in list_2 (means that
         after each node in the entire list_2 has been checked and
         still not found)
         output something like <tag-name xsi:nil = "true"/> (only one
                  output instead of print it out each time when
                  list_1:Id !=list_2:Id)

I know that there is no "break" in xslt for the for-loop. How can I get this?

Any hint and tip are appreciated.

Lxu


 
Old January 15th, 2004, 05:24 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I don't have the solution you asked for but I can suggest this. You can compare sets directly without looping. If you ask whether a node is equal to a node set you get true if there exists in that set a node whose string value is the same as the one of the single node. If you test whether they are not equal then you test that at least one node in the set does not equal that of the single node. You can also test whether no nodes are equal using not function.

Examples:

Use this data
Code:
<data>
  <items>
    <item id="id1">Item One</item>
    <item id="id2">Item Two</item>
    <item id="id3">Item Three</item>
    <item id="id4">Item Four</item>
  </items>
  <target1 id="id3"/>
  <target2 id="id5"/>
</data>
Run with this stylesheet:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/"><xsl:text>#x0a;</xsl:text>    
    target1/@id = items/item/@id: <xsl:value-of select="data/target1/@id = data/items/item/@id"/><xsl:text>#x0a;</xsl:text>
    target1/@id != items/item/@id: <xsl:value-of select="data/target1/@id != data/items/item/@id"/><xsl:text>#x0a;</xsl:text>  
    not(target1/@id = items/item/@id): <xsl:value-of select="not(data/target1/@id = data/items/item/@id)"/><xsl:text>#x0a;</xsl:text>
    *****************
    target2/@id = items/item/@id: <xsl:value-of select="data/target2/@id = data/items/item/@id"/><xsl:text>#x0a;</xsl:text>
    target2/@id != items/item/@id: <xsl:value-of select="data/target2/@id != data/items/item/@id"/><xsl:text>#x0a;</xsl:text>  
    not(target2/@id = items/item/@id): <xsl:value-of select="not(data/target2/@id = data/items/item/@id)"/><xsl:text>#x0a;</xsl:text>    
  </xsl:template>
</xsl:stylesheet>
Joe (MVP - xml)
 
Old January 15th, 2004, 12:32 PM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much! Your seggestion is really helpful. I have it done. :-)

Lx

 
Old January 15th, 2004, 12:57 PM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One more question:

Here is my code in a xslt file,
<xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
…
…
<xsl:element name="Part-MaterialDefiningDocument">
   <xsl:attribute name="xsi:nil">
       <xsl:value-of select='true'"/>
   </xsl:attribute>
</xsl:element>

…
…
</xsl:stylesheet>

Here is the output,
<Part-MaterialDefiningDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

I want to the output to be in this way,
<Part-MaterialDefiningDocument xsi:nil="true"/>

How can I get rid of xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" from my output

Thanks for the helps!

LX


 
Old January 16th, 2004, 05:58 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can't, you're using xsi:nil in the output so the namespace needs declaring.

Joe (MVP - xml)
 
Old January 16th, 2004, 10:38 AM
lxu lxu is offline
Authorized User
 
Join Date: Oct 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see. Thanks!

Lx






Similar Threads
Thread Thread Starter Forum Replies Last Post
help: how can I break from xsl for-each loop ? back2grave XSLT 5 May 31st, 2012 12:03 PM
help with 'break' Manu Sharma Beginning PHP 3 March 15th, 2007 09:04 PM
how do i break it up? kuehhc Beginning PHP 3 January 19th, 2005 09:52 AM
Unable to Break at Break point Girishbk VB.NET 2002/2003 Basics 0 January 18th, 2005 08:29 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.