Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 25-10-2008
Member
 
Join Date: Aug 2006
Posts: 122
problem in merging two sequences in xslt

Hi,
i have some xml
that looks like this:

<parent>
<a>1,2,3,4,5,6,7,8</a>
<b>a,b,c,d,e,f,g,h</b>
</parent>

what i need i this:
<parent>
<ab>a 1 b 2 c 3 d 4 ...</ab>
</parent>

How can i do this? I thought of tokenizing the values of <a> and <b> into sequences, but i don't know how to merge them together.
Does anybody has a solution to this problem?
Reply With Quote
  #2  
Old 25-10-2008
Member
 
Join Date: May 2008
Posts: 2,293
Re: problem in merging two sequences in xslt

May be using fn:string-join ?

http://www.xqueryfunctions.com/xq/fn_string-join.html
Reply With Quote
  #3  
Old 25-10-2008
Member
 
Join Date: Aug 2006
Posts: 122
Re: problem in merging two sequences in xslt

Well, to use fn:string join i would still need to first merge the two sequences together wouldn't i?
Reply With Quote
  #4  
Old 25-10-2008
Member
 
Join Date: May 2008
Posts: 2,008
Re: problem in merging two sequences in xslt

<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlnss="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">

<xsl:template match="parent">
<xsl:copy>
<xsl:variable name="l1" as="xs:string*" select="tokenize(a, ',')"/>
<xsl:variable name="l2" as="xs:string*" select="tokenize(b, ',')"/>
<ab>
<xsl:value-of select="for $p in 1 to count($l1) return
($l2[$p], $l1[$p])" separator=" "/>
</ab>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Reply With Quote
  #5  
Old 25-10-2008
Member
 
Join Date: Aug 2006
Posts: 122
Re: problem in merging two sequences in xslt

Hi katty

thanks for your reply. Its actually not yet working for me. l1 and l2 are of count==1 so what i get is pretty much what i put in. There
seems to be a problem with assigning the sequences to the variables.Can you fix it?
Reply With Quote
  #6  
Old 25-10-2008
Member
 
Join Date: Aug 2006
Posts: 122
Re: problem in merging two sequences in xslt

can i change the datatypes of the lists, so that i can do something like
<xsl:value-of select="for $p in 1 to count($l1) return ($l2[$p] div
10 , $l1[$p] div 10)" separator=" "/> ?
Reply With Quote
  #7  
Old 25-10-2008
Member
 
Join Date: May 2008
Posts: 2,008
Re: problem in merging two sequences in xslt

I don't understand how you expect the values a,b,c and so on to be treated as numbers.However let's assume you have different input data

<parent>
<a>1,2,3,4,5,6,7,8</a>
<b>10,20,30,40,50,60,70,80</b>
</parent>

then you can of course convert the string sequence the tokenize function gives you to a number sequence:

<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlnss="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">

<xsl:template match="parent">
<xsl:copy>
<xsl:variable name="l1" as="xs:double*" select="for $item in
tokenize(a, ',') return xs:double($item)"/>
<xsl:variable name="l2" as="xs:double*" select="for $item in
tokenize(b, ',') return xs:double($item)"/>
<ab>
<xsl:value-of select="for $p in 1 to count($l1) return ($l2[$p]
div 10, $l1[$p] div 10)" separator=" "/>
</ab>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "problem in merging two sequences in xslt"
Thread Thread Starter Forum Replies Last Post
Resident Evil The Mercenaries 3D: Death Sequences Namkar Video Games 7 28-07-2011 11:02 PM
Setting Printer Escape Sequences in Vb6 Avinash Kaur Software Development 4 08-04-2009 02:28 PM
problem with xml et xslt manjava Software Development 0 28-12-2008 05:26 PM
XML ,XSL, XSLT problem MarceloQuad Software Development 2 25-10-2008 04:26 PM


All times are GMT +5.5. The time now is 12:42 AM.