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 13th, 2012, 07:31 AM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default breakinf the iteration

Hi,

I need some help with the following
input xml
<document>
<item>
<itemdata>text/plain plain text data sample 1</itemdata>
</item>
<item>
<itemdata>text/plain plain text data sample 2 </itemdata>
</item>
<item>
<itemdata>text/html html data sample 1</itemdata>
</item>
<item>
<itemdata>text/plain plain text data sample 3</itemdata>
</item>
</document>

(the data in each itemdata node is encoded therefore it's not easy do a straight forward test.)

i want to iterate through the itemdata nodes and do the following
1) if there is 'text/html' in the data then break the iteration and just display the html output ( in this case text/html html data sample 1)
2) if there's no 'text/html' then out put
text/plain plain text data sample 1
text/plain plain text data sample 2
text/plain plain text data sample 3

any assistance would be very much appreciated.

thanks you
 
Old January 13th, 2012, 10:50 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's no iteration in XSLT, only functional mapping; therefore you can't "break" an iteration. (Think of xsl:for-each as effectively processing all the selected items in parallel).

Since you haven't given your real input data I can't give you a concrete answer. It looks to me as if you can select the items you need to process and then process them, ignoring the others: for example in psuedocode

if exists(itemData[. = 'text/plain html']
then process(itemData[. = 'text/plain html'][1]
else process(itemData[. = text/plain text']
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 13th, 2012, 11:18 AM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thank you for your reply. The input data contains encoded messages which have to be decoded ( some times twice) to check whether it's html or non html data. therefore i'm unable to do the check on the text.

eg <itemData>DgAKAAAAygAIAAIA0wBmcm9tIHVrYXN3YXNwMDIu dHJhdnAubmV0IChbMTAuMTEwLjEyMC4xODRd
KSAgICAgICAgICBieSB1a2FzbGRocDAxLmV1cHJvZC50cmF2cC 5uZXQgKExvdHVzIERvbWlubyBS
ZWxlYXNlIDcuMC4zKSAgICAgICAgICB3aXRoIEVTTVRQIGlkID IwMTAxMTIzMTYyODAwOTItMjA5
MzggOyAgICAgICAgICBUdWUsIDIzIE5vdiAyMDEwIDE2OjI4Oj AwICswMDAwUmVjZWl2ZWQ6IGZy
....</itemData>


Currently my output contains both the html and non html data. I tried to save the results after every decode to a result tree and then read it form there but getting errors in java



<xsl:varaible name = outputNode>
<!--doing the decoding and if the data is html store it in
<htmlText>
else store it in <plainText>
</xsl:variable>
<xsl:variable name="output">
<xsl:choose>
<xsl:when test="exsl:node-set($outputNode/htmlText)">
<xsl:value-of select="exsl:node-set($outputNode/htmlText[1])"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="exsl:node-set($outputNode/plainText)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<span><xsl:value-of select="$output"/></span>
 
Old January 13th, 2012, 11:59 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Then you need a multi-pass solution: decode the data on the first pass, select it on the second.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
add a value in each iteration chameleon XSLT 2 August 29th, 2009 02:19 PM
iteration bostek Excel VBA 5 August 30th, 2006 01:23 AM
iteration movenext weazy Excel VBA 0 June 9th, 2006 05:56 PM
Picture iteration bahachin Excel VBA 3 September 28th, 2005 12:44 PM
Iteration in struts sridevi Servlets 2 July 1st, 2005 07:01 AM





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