Results 1 to 7 of 7

Thread: problem in merging two sequences in xslt

  1. #1
    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?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: problem in merging two sequences in xslt


  3. #3
    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?

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    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>

  5. #5
    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?

  6. #6
    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=" "/> ?

  7. #7
    Join Date
    May 2008
    Posts
    2,012

    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>

Similar Threads

  1. Resident Evil The Mercenaries 3D: Death Sequences
    By Namkar in forum Video Games
    Replies: 7
    Last Post: 28-07-2011, 11:02 PM
  2. Setting Printer Escape Sequences in Vb6
    By Avinash Kaur in forum Software Development
    Replies: 4
    Last Post: 08-04-2009, 02:28 PM
  3. problem with xml et xslt
    By manjava in forum Software Development
    Replies: 0
    Last Post: 28-12-2008, 05:26 PM
  4. XML ,XSL, XSLT problem
    By MarceloQuad in forum Software Development
    Replies: 2
    Last Post: 25-10-2008, 04:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,980,047.71197 seconds with 16 queries