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

XSLT problem: how to transfer from XML to XML?

Leo
I would like to transfer my XML file into another XML which has a struct like this:
<catalog>
<media>
<cd>myCD</cd>
</media>
</catalog>

However using my XSLT I could only get:

<catalog>myCD</catalog>

Can you please point out where my problem is? Thanks very much in advance.

Leo

<xsl:template name="catalog">
<xsl:call-template name="mytemplate">
<xsl:with-param name="ename">catalog</xsl:with-param>
<xsl:with-param name="evalue">
<xsl:choose>
<xsl:when test="/myxpath">
<xsl:call-template name="mytemplate">
<xsl:with-param name="ename">media</xsl:with-param>
<xsl:with-param name="evalue">
<xsl:call-template name="mytemplate">
<xsl:with-param name="ename">cd</xsl:with-param>
<xsl:with-param name="evalue" select="/myxpath1"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
...

<xsl:template name="mytemplate">
<xsl:param name="etext"/>
<xsl:param name="ename"/>
<xsl:param name="evalue"/>
<xsl:if test="($evalue!='') and ($evalue!='none')">
<xsl:element name="{$ename}">
<xsl:if test="($etext!='')">
<xsl:value-of select="$etext"/>
</xsl:if>
<xsl:value-of select="$evalue"/>
</xsl:element>
</xsl:if>
</xsl:template>
Jul 20 '05 #1
2 1504
Leo wrote:
I would like to transfer my XML file into another XML which has a struct like this:
<catalog>
<media>
<cd>myCD</cd>
</media>
</catalog>

However using my XSLT I could only get:

<catalog>myCD</catalog>

Can you please point out where my problem is?


Not yet. It's not clear what you're starting with or how the XSLT you
posted relates to the input. Generally speaking, I'd advise using
apply-templates rather than call-template wherever possible. In my
experience, it tends to produce a clearer, cleaner solution. Also, I'm
guessing that maybe the problem you're experiencing has to do with using
value-of instead of copy-of somewhere, but I couldn't figure it out from
what you posted.

You might try synthesizing the problem down to a very small but complete
set of files (input, output, transform) and posting that. Or you could
simply try posting input and desired output and see what others come up
with.

For me, I often find that I figure out the answer on my own during the
process of trying to explain it to someone else, so it can be a useful
technique even if you don't post a thing. Good luck!

Ed

Jul 20 '05 #2


value-of generates the string value of its argument

so you may want to change

<xsl:value-of select="$evalue"/>

to

<xsl:copy-of select="$evalue"/>

although I suspect that your xslt is far more complicated than you need,
although it's hard to say as you don't say what transformation you are
performing.

David

Jul 20 '05 #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...
0
by: Mike | last post by:
I'm generating an XSLT document programatically in VB.Net. I'm then trying to apply that XSLT against a cXML document to generate my own internally developed XML document. I'm using RichTextBox...
4
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
3
by: Chris | last post by:
Hi, I have an XML-file : <book> <title>Alaska</title> </book> I would like transfer the <book>-elements to <bookname> using an xsl-sheet, thus producing xml-again. and saving the output in...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
4
by: WStoreyII | last post by:
I wish to know how to set it up so that when an xml webservice is called that instead of displaying the xml in the browser it will render it with a xslt file the problem is i dont know how to do...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
3
by: Wizfrog | last post by:
Hello, I'm unsing well-formed XML HTML tags as my formatted "Description" content in a XML Database, so I have stuff of the sort: <Description lang='en'><b>This is bold Text</band this is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.