[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

[no subject]

[no subject]
Essentially, the solution provided does not "Terminate" a for-each or
any such. This is not possible in XSL. What the solution does,
instead, is to choose only the elements that are to be included in the
for-each, totally bypassing those that are not desired.

An example of the difference between procedural programming and
declerative/functional programming:

We want those elem that have numeric values less than or equal 3.

Input:

<?xml version="1.0"?>
<root>
  <elem val="1">Something</elem>
  <elem val="2">Something</elem>
  <elem val="3">Something</elem>
  <elem val="4">Something</elem>
  <elem val="5">Something</elem>
</root>

Procedural solution would be (pseudocode):
<xsl:template match="root">
  <xsl:for-each select="elem">
    <xsl:if test="number(@val) &lt;=3"><xsl:terminate/></xsl:if> <!--
Will not work! -->
    <!-- generate output here -->
  </xsl:for-each>
</xsl:template>

Functional solution, which chooses only the elements to use:
<xsl:template match="root">
  <xsl:for-each select="elem[number(@val) &lt;=3]"> <!-- Here is the
difference -->
    <!-- generate output here -->
  </xsl:for-each>
</xsl:template>

You can use keys to generate an index over the chosen elements for
faster processing, but the generics behind the two approaches are, in
this matter, the same. So a short answer to your question would be
"Yes, you can use keys, as well as other approaches".

I would advice you to make a simple test case (with simple names and
simple structure), and try to solve this. When you understand that,
you can make the case more and more like your real world problem,
until it is solved.
If you have problems, you will have a much better chance of help, if
you post a simple case with desired output, and where you are stuck
with your XSL (simple as well).

Regards,
Ragulf Pickaxe :-)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.