XSL Transformation output -- no tags -- Help!

Discussion in 'XML' started by Mike Conmackie, Apr 28, 2004.

  1. Hi Folks,

    I've probably omitted something very basic but I have no idea what it might
    be. The results of my transformation _should_ be an xml file but all I get
    is the xml declaration immediately followed by the input node text values in
    one long string -- no xml tags (barring the xml declaration, of course)
    appear in the output file. Anyone who wants to see either the input xml
    file or the xsl file, please let me know and I will e-mail them to you.
    Thanks.

    Regards,

    Mike Conmackie
     
    Mike Conmackie, Apr 28, 2004
    #1
    1. Advertising

  2. Mike Conmackie

    dan Guest

    "Mike Conmackie" <> wrote in message news:<408ff79d$1@10.10.0.241>...
    <snip>
    > The results of my transformation _should_ be an xml file but all I get
    > is the xml declaration immediately followed by the input node text values in
    > one long string

    <snip>


    I would guess you are using <xsl:value-of> when what it sounds like
    you need is <xsl:copy-of>
     
    dan, Apr 28, 2004
    #2
    1. Advertising

  3. Dan,

    The purpose of the transformation is to translate one tag set into another
    (with slightly different output structure). Therefore, I don't think that
    <xsl:copy-of> is what I want. Would you like to look at the input document
    and the stylesheet? I can also show you a sample of the expected output.

    Mike

    "dan" <> wrote in message
    news:...
    > "Mike Conmackie" <> wrote in message

    news:<408ff79d$1@10.10.0.241>...
    > <snip>
    > > The results of my transformation _should_ be an xml file but all I get
    > > is the xml declaration immediately followed by the input node text

    values in
    > > one long string

    > <snip>
    >
    >
    > I would guess you are using <xsl:value-of> when what it sounds like
    > you need is <xsl:copy-of>
     
    Mike Conmackie, Apr 28, 2004
    #3
  4. Hi again,

    "Mike Conmackie" <> writes:
    > I've probably omitted something very basic but I have no idea what it might
    > be. The results of my transformation _should_ be an xml file but all I get
    > is the xml declaration immediately followed by the input node text values in
    > one long string -- no xml tags (barring the xml declaration, of course)
    > appear in the output file. Anyone who wants to see either the input xml
    > file or the xsl file, please let me know and I will e-mail them to you.


    This is what happens when no template in your XSL transformation
    matches anything in the input XML - the built-in template rules
    take over, which basically just copy the node contents.
    See http://www.w3.org/TR/xslt#built-in-rule

    Example:

    This XML:
    <a>
    <b>Some stuff</b>
    <c>Some other stuff</c>
    </a>


    With this XSLT:
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >


    <!-- Main template matches nothing in the input -->
    <xsl:template match="/x">
    <xsl:text>Hello, world!</xsl:text>
    </xsl:template>

    </xsl:stylesheet>


    Gives this output:
    <?xml version="1.0" encoding="UTF-8"?>
    Some stuff
    Some other stuff


    Ie. just a copy of the node contents. Note that we *don't* see
    "Hello, world!" which shows that the main template was did not match
    anything.

    This might be your problem. If you stick in a recursive copy it will
    over-ride the built-in rules and match anything not already matched by
    other templates. Therefore nodes you don't explicitly process are
    just copied to the output (the identity transformation)

    This is the version given in the W3C Rec:
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>


    However, I prefer this two-template one as I generally don't want to
    copy namespaces to my output:
    <xsl:template match="node()">
    <xsl:element name="{name()}">
    <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
    </xsl:template>

    <xsl:template match="@*|text()|comment()|processing-instruction()">
    <xsl:copy/>
    </xsl:template>


    Ben

    --
    Ben Edgington
    Mail to the address above is discarded.
    Mail to ben at that address might be read.
    http://www.edginet.org/
     
    Ben Edgington, Apr 29, 2004
    #4
  5. Hello All,

    Ben's statement regarding the non-matching status of any template in the
    stylesheet was the real issue. I removed the namespace prefix from the
    input document and the styelsheet and life became much better. As usual,
    thanks to all who offered assistance.

    Mike
     
    Mike Conmackie, Apr 29, 2004
    #5
    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. coincoin
    Replies:
    0
    Views:
    598
    coincoin
    Aug 5, 2003
  2. Greg Smith
    Replies:
    35
    Views:
    3,224
    Alex Kay
    Oct 24, 2004
  3. yannicklaclau
    Replies:
    2
    Views:
    547
    yannicklaclau
    Feb 28, 2005
  4. Replies:
    0
    Views:
    583
  5. Replies:
    0
    Views:
    560
Loading...

Share This Page