XSLT problem: how to transfer from XML to XML?

Discussion in 'XML' started by Leo, Jan 17, 2005.

  1. Leo

    Leo Guest

    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>
     
    Leo, Jan 17, 2005
    #1
    1. Advertising

  2. Leo

    Ed Beroset Guest

    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
     
    Ed Beroset, Jan 17, 2005
    #2
    1. Advertising

  3. 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
     
    David Carlisle, Jan 17, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    773
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,751
    Dimitre Novatchev
    Sep 25, 2003
  3. Replies:
    4
    Views:
    716
  4. jkflens
    Replies:
    2
    Views:
    1,548
    jkflens
    May 30, 2006
  5. Jim
    Replies:
    1
    Views:
    993
    Aaron Bertrand - MVP
    Jan 28, 2004
Loading...

Share This Page