473,320 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 <aand <b>
into sequences, but i dont know how to merge them together.
Does anybody has a solution to this problem?

cheers, Johannes
Oct 15 '08 #1
7 2260
May be using fn:string-join ?

http://www.xqueryfunctions.com/xq/fn_string-join.html

JMan wrote:
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 <aand <b>
into sequences, but i dont know how to merge them together.
Does anybody has a solution to this problem?

cheers, Johannes
Oct 15 '08 #2
Well, to use fn:string join i would still need to first merge the two
sequences together wouldn't i?

cheers, Johannes

On 15 Okt., 16:42, dahu <d...@dahu.frwrote:
May be using fn:string-join ?

http://www.xqueryfunctions.com/xq/fn_string-join.html

JMan wrote:
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 <aand <b>
into sequences, but i dont know how to merge them together.
Does anybody has a solution to this problem?
cheers, Johannes
Oct 15 '08 #3
JMan wrote:
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 <aand <b>
into sequences, but i dont know how to merge them together.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="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>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 15 '08 #4
Hi Martin,

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 assiging the sequences to the veriables.
Can you fix it?

thanks, Johannes
JMan wrote:
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 <aand <b>
into sequences, but i dont know how to merge them together.

<xsl:stylesheet
* *xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
* *xmlns:xs="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>

--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
Oct 15 '08 #5
Martin!
thanks alot!

cheers, Johannes

On 15 Okt., 17:02, Martin Honnen <mahotr...@yahoo.dewrote:
JMan wrote:
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 <aand <b>
into sequences, but i dont know how to merge them together.

<xsl:stylesheet
* *xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
* *xmlns:xs="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>

--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
Oct 15 '08 #6
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=" "/?

cheers, Johannes

On 15 Okt., 18:09, JMan <JohannesElsingho...@gmail.comwrote:
Martin!
thanks alot!

cheers, Johannes

On 15 Okt., 17:02, Martin Honnen <mahotr...@yahoo.dewrote:
JMan wrote:
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 <aand <b>
into sequences, but i dont know how to merge them together.
<xsl:stylesheet
* *xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
* *xmlns:xs="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>
--
* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
Oct 15 '08 #7
JMan wrote:
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=" "/?
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
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="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>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 15 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mael Guillemot | last post by:
Hi, I have one xml looking like this: ========================= <video> <shot id="1"> <timestampbegin>000030.90</timestampbegin> <feature>blabla</feature>...
3
by: William Ahern | last post by:
I'm looking for resources on splitting and merging XML trees. Specifically, on methods to pare large XML documents into smaller documents which can be merged later. Off of the top of my head, I...
1
by: Yannick Patois | last post by:
Hi, I would like to merge two XML document, or more exacly enrich a document by inheritiong from another. I read a bit about XSLT and I know a bit of python/sax/dom, and I dont know where I...
24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
4
by: rottyguy70 | last post by:
hello, am trying to do the following with little success. any help is appreciated. 1) assume i have a static mapping: a -> 1 b -> 2 c -> 3 2) i need to read through some data, let's say...
2
by: Cy Huckaba | last post by:
I have an XML document that is linked to other document and I can't figure out what the best way to try and merge them before query qith an XpathNavigator. Simple example...a root xml document...
3
by: Robert Strickland | last post by:
I need to merge 3 or more xml streams (I have 4 string variables that contain xml) into a single xml stream before doing a transformation. Is there any sample code or site to show the way? Thanks
2
by: Nikhil Prashar | last post by:
I'm trying to merge two XML files that have the same structure but not necessarily the same nodes in the same order. I've tried opening the files as datasets and using the DataSet.Merge() function,...
2
by: daniel.knights | last post by:
Hello, I was wondering if anyone could shed some light on an issue I am having. I have 3 or 4 xml files which i need to merge onto another xml file called build_log.xml, which is produced using...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.