XSLT problem: how to transfer from XML to XML?

L

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>
 
E

Ed Beroset

Leo said:
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
 
D

David Carlisle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top