473,387 Members | 1,493 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,387 software developers and data experts.

help with XSLT

Hi to all I need to transform an xml document from a format to another.

In my source XML I have a tag value that is a list of codes. I give u
an example:
<mytag>1,2,33,44,55,6,7,88,99,...,nn</mytag>

Now I need to have this tag transformed as follow:
<MyNewTags>
<MyNewTag>1</MyNewTag>
<MyNewTag>2</MyNewTag>
<MyNewTag>33</MyNewTag>
<MyNewTag>44</MyNewTag>
<MyNewTag>55</MyNewTag>
<MyNewTag>6/MyNewTag>
<MyNewTag>7</MyNewTag>
<MyNewTag>88</MyNewTag>
<MyNewTag>99</MyNewTag>
....
<MyNewTag>nn</MyNewTag>
</MyNewTags>

How do i do that with XSLT?
Or when can I lookup to find the solution?

I did not find anything on the W3C Tutorial about XSLT..

Thanks in advance, Himgi.

Aug 1 '06 #1
2 1000
himgi wrote:
In my source XML I have a tag value that is a list of codes. I give u
an example:
<mytag>1,2,33,44,55,6,7,88,99,...,nn</mytag>
This is an awkward problem in XSLT (not hard, just awkward). Your
input document is more of a text document than an XML document, because
the "interesting" part of the parsing is about parsing a text string,
not XML.

Here's a crude recursive solution.

<xsl:template name="foo" >
<xsl:param name="list" select="/.." />
<xsl:variable name="car" select="substring-before($list,',')" />
<xsl:variable name="cdr" select="substring-after($list,',')" />
<xsl:choose><xsl:when test="$car" >
<MyNewTag><xsl:value-of select="($car)" /></MyNewTag>
<xsl:call-template name="foo" >
<xsl:with-param name="list" select="($cdr)" />
</xsl:call-template>
</xsl:when>
<xsl:when test="$list" ><MyNewTag><xsl:value-of select="$list"
/></MyNewTag></xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="mytag" >
<MyNewTags>
<xsl:call-template name="foo" >
<xsl:with-param name="list" select="text()" />
</xsl:call-template>
</MyNewTags>
</xsl:template>

Aug 1 '06 #2

Andy Dingley ha scritto:
himgi wrote:
In my source XML I have a tag value that is a list of codes. I give u
an example:
<mytag>1,2,33,44,55,6,7,88,99,...,nn</mytag>

This is an awkward problem in XSLT (not hard, just awkward). Your
input document is more of a text document than an XML document, because
the "interesting" part of the parsing is about parsing a text string,
not XML.

Here's a crude recursive solution.

<xsl:template name="foo" >
<xsl:param name="list" select="/.." />
<xsl:variable name="car" select="substring-before($list,',')" />
<xsl:variable name="cdr" select="substring-after($list,',')" />
<xsl:choose><xsl:when test="$car" >
<MyNewTag><xsl:value-of select="($car)" /></MyNewTag>
<xsl:call-template name="foo" >
<xsl:with-param name="list" select="($cdr)" />
</xsl:call-template>
</xsl:when>
<xsl:when test="$list" ><MyNewTag><xsl:value-of select="$list"
/></MyNewTag></xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="mytag" >
<MyNewTags>
<xsl:call-template name="foo" >
<xsl:with-param name="list" select="text()" />
</xsl:call-template>
</MyNewTags>
</xsl:template>
Thank you very much. I really appreciate!

Aug 2 '06 #3

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

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
4
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
5
by: dennis | last post by:
Hi, First of all, hi to you all. I'm working on a Delphi project wich is becoming near it's deadline. I have a very simple XSLT question wich i hope one of you folks can help me with? The...
5
by: | last post by:
Hello Guys, I am trying to render an Xml dataset into HTML using XSLT. When I am loading the XSLT file into transform object to render it. Here is the code snippet: <!-- XslTransform...
7
by: Roshawn Dawson | last post by:
Hi, I have an xslt file located in the root directory. It is used by an aspx pages in both the root directory and a subdirectory. But for some strange reason, the aspx page in the subdirectory...
1
by: byquestion | last post by:
Hi there xslt gurus, i am kinda new to xslt and having difficulty to implement my some iterations. i need to recreate an xml file by using xslt. here is the sample xml file(input for xslt) ...
6
Gaiason
by: Gaiason | last post by:
Hi XML/XSLT masters and gurus, I am a newbie in XML/XSLT and have been reading up XML/XSLT in order to convert a XML generated from a OCR engine to another format of XML. I am truly stuck at this...
2
by: milecimm | last post by:
Hello, I need some help to solve the following problem (if it is possible, that's it): I'm using a xpath expression to programatically get data from my xml file. I want to transform ONLY the...
4
by: Nick | last post by:
I have a critical requirement where I need to club together 4 xml files and display them in an sibngle HTML report. The xmls are generated by Java application by a normal file I/O. Is there a...
2
Dormilich
by: Dormilich | last post by:
Hi, I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means: Error: Fatal error: Can't use method return value in write context in "output.php" on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.