XSLT SPLIT function ?

  • Johan1974
  • Born
  • Born
  • Johan1974
  • Posts: 1

Post 3+ Months Ago

Hello,

Is it possible to use xslt to go from

Code:
Code: [ Select ]
<XML>
 <Name>Name1;Name2</Name>
 <Adress>Adress1;Adress2</Adress>
</XML>
  1. <XML>
  2.  <Name>Name1;Name2</Name>
  3.  <Adress>Adress1;Adress2</Adress>
  4. </XML>

To this

Code:
Code: [ Select ]
<XML>
  <LINE>
    <Name>Name1</Name>
    <Adress>Adress1</Adress>
   </LINE>
   <LINE>
    <Name>Name2</Name>
    <Adress>Adress2</Adress>
   </LINE>
</XML>
  1. <XML>
  2.   <LINE>
  3.     <Name>Name1</Name>
  4.     <Adress>Adress1</Adress>
  5.    </LINE>
  6.    <LINE>
  7.     <Name>Name2</Name>
  8.     <Adress>Adress2</Adress>
  9.    </LINE>
  10. </XML>

Any help would be most appreciated.

Johan
Moderator Remark: Added code wrappers
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Not with any of the standard selectors. It will be easier to write a script that fixes the XML input than it will be to find and figure out any non-standard XSL based solutions.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

I would agree with joebert on that it would be easier to write a script to fix the input. I haven't messed with XSLT for a bit and the only thing I could dig up was using a tokenizer and a for loop. I'm not sure if that would help or not.

This is what I dug up.
XML Code: [ Select ]
 
<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:output method="text"/>
 
  <xsl:template match="/">
 
    <xsl:variable name="sampleString">XML,XSLT,XPath,SVG,XPointer</xsl:variable>
 
    <xsl:variable name="tokenizedSample" select="tokenize($sampleString,',')"/>
 
    <xsl:for-each select="$tokenizedSample">
      <xsl:value-of select="."/>
      <xsl:text>! </xsl:text>
    </xsl:for-each>
 
Second item in tokenizedSample:
    {<xsl:value-of select="item-at($tokenizedSample,2)"/>}
 
Tenth item in tokenizedSample:
    {<xsl:value-of select="item-at($tokenizedSample,10)"/>}
 
Position of SVG in tokenizedSample:
    {<xsl:value-of select="index-of($tokenizedSample,'SVG')"/>}
 
Position of XSL-FO in tokenizedSample:
    {<xsl:value-of select="index-of($tokenizedSample,'XSL-FO')"/>}
 
End of test.
  </xsl:template>
 
</xsl:stylesheet>
 
  1.  
  2. <xsl:stylesheet version="2.0"
  3.  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.  
  5.   <xsl:output method="text"/>
  6.  
  7.   <xsl:template match="/">
  8.  
  9.     <xsl:variable name="sampleString">XML,XSLT,XPath,SVG,XPointer</xsl:variable>
  10.  
  11.     <xsl:variable name="tokenizedSample" select="tokenize($sampleString,',')"/>
  12.  
  13.     <xsl:for-each select="$tokenizedSample">
  14.       <xsl:value-of select="."/>
  15.       <xsl:text>! </xsl:text>
  16.     </xsl:for-each>
  17.  
  18. Second item in tokenizedSample:
  19.     {<xsl:value-of select="item-at($tokenizedSample,2)"/>}
  20.  
  21. Tenth item in tokenizedSample:
  22.     {<xsl:value-of select="item-at($tokenizedSample,10)"/>}
  23.  
  24. Position of SVG in tokenizedSample:
  25.     {<xsl:value-of select="index-of($tokenizedSample,'SVG')"/>}
  26.  
  27. Position of XSL-FO in tokenizedSample:
  28.     {<xsl:value-of select="index-of($tokenizedSample,'XSL-FO')"/>}
  29.  
  30. End of test.
  31.   </xsl:template>
  32.  
  33. </xsl:stylesheet>
  34.  


Found here http://www.xml.com/pub/a/2003/05/07/tr.html

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 19 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.