473,325 Members | 2,342 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,325 software developers and data experts.

xsl transformation - separating a value

15
Hi all,
I am having bit of a problem separating a value in xml by xsl transformation.

An example xml file:
<foo name="def[1]/hij[2]/klm[1]">
</foo>

And what all I want to do is transform this xml to take the attribute name value each separated by '/'
like -
def[1]
hij[2]
klm[1]

Note that the number inside the bracket and the items inside the name value can vary.
Any suggestions or help will be much appreciated!

Thanks!
May 7 '08 #1
2 1387
jkmyoung
2,057 Expert 2GB
Standard recursive template:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="split">
  2.   <xsl:param name="str"/>
  3.   <xsl:param name="delim"/>
  4.   <xsl:choose>
  5.     <xsl:when test="contains($str, $delim)">
  6.       <xsl:value-of select="substring-before($str, $delim)"/>
  7.       <xsl:call-template name="split">
  8.         <xsl:with-param name="str" select="substring-after($str, $delim)"/>
  9.         <xsl:with-param name="delim" select="$delim"/>
  10.       </xsl:call-template>
  11.     </xsl:when>
  12.     <xsl:otherwise>
  13.        <xsl:value-of select="$str"/>
  14.     </xsl:otherwise>
  15.   </xsl:choose>
  16. </xsl:template>
  17.  
Call it like so:
Expand|Select|Wrap|Line Numbers
  1. <xsl:call-template name="split">
  2.   <xsl:with-param name="str" select="@name"/>
  3.   <xsl:with-param name="delim" select="'/'"/>
  4. </xsl:call-template>
  5.  
May 8 '08 #2
MedIt
15
Standard recursive template:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="split">
  2.   <xsl:param name="str"/>
  3.   <xsl:param name="delim"/>
  4.   <xsl:choose>
  5.     <xsl:when test="contains($str, $delim)">
  6.       <xsl:value-of select="substring-before($str, $delim)"/>
  7.       <xsl:call-template name="split">
  8.         <xsl:with-param name="str" select="substring-after($str, $delim)"/>
  9.         <xsl:with-param name="delim" select="$delim"/>
  10.       </xsl:call-template>
  11.     </xsl:when>
  12.     <xsl:otherwise>
  13.        <xsl:value-of select="$str"/>
  14.     </xsl:otherwise>
  15.   </xsl:choose>
  16. </xsl:template>
  17.  
Call it like so:
Expand|Select|Wrap|Line Numbers
  1. <xsl:call-template name="split">
  2.   <xsl:with-param name="str" select="@name"/>
  3.   <xsl:with-param name="delim" select="'/'"/>
  4. </xsl:call-template>
  5.  
Thanks for your help!
I have come across something similar to what you have shown.
Cheers!
May 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
4
by: Kevin Dean | last post by:
I'm trying to create an XSL transformation that will strip out development-specific attributes from deployment descriptors and other XML files. I have already successfully done so with web.xml but...
8
by: Will | last post by:
I was thrust into XML about 2 weeks ago and don't know much yet. From another department in the corp I am receiving an XML file which concatenates nodes all on one line i.e....
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
4
by: Rushi | last post by:
Hi friends, I'm beginner in XSL/XSLT. And i m very impressive, as it is separating presentation and data layer. Now my question is related to XSL transform. Below are sample files one is...
6
by: dave | last post by:
I really have 2 questions regarding the following xml snippet. The xml is a directory representation. <?xml version="1.0" standalone="yes"?> <FileSystem> <Row> <ID>1</ID> <Name>Root</Name>...
14
by: Thomas Bauer | last post by:
Hello, I search a example like that. (1,0,0,1,4,5 ) -- moving (1,0,0,1,0,0 ) -- normal matrix (-1,0,0,1,0,0 ) -- Mirror Y-Axis (0,-1,0,1,0,0 ) -- Mirror X-Axis I caluculate all in mm.
2
by: abhimanyu singh | last post by:
i m facing a serious probs now a days............ its seems easy but for me i found it difficult......... i want to do transformation usig xsl and xml(adding parameter). for IE its working fine...
1
by: boetke | last post by:
Hi all, I am attempting to create an xslt transformation which I am having trouble with. I am fairly new to xslt and am having a hard time getting my head around it. The original xml file looks...
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
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...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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...
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.