XSLT: transforming a document into itself

Discussion in 'XML' started by samppi, Jan 6, 2008.

  1. samppi

    samppi Guest

    I'm teaching myself XSLT right now, but, just as part of learning, I'm
    trying to figure out how one would transform a document an identical
    document.

    This doesn't work:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform">

    <xsl:template match="/">

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

    </xsl:template>

    </xsl:stylesheet>

    ....but I can't figure out how else one would do it.

    Thanks in advance!
    samppi, Jan 6, 2008
    #1
    1. Advertising

  2. samppi wrote:
    > I'm teaching myself XSLT right now, but, just as part of learning, I'm
    > trying to figure out how one would transform a document an identical
    > document.
    >
    > This doesn't work:
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    > Transform">
    >
    > <xsl:template match="/">
    >
    > <xsl:value-of select="/"/>


    Well xsl:value-of outputs the string value of the selected node. If you
    want to copy the complete document then use
    <xsl:copy-of select="/"/>
    instead. That copies everything the XSLT/XPath data model knows about.


    You should also learn about the identity transformation template
    <xsl:template match="@* | node()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>
    as that also copies everything but allows you to add templates to
    override the behaviour e.g. to change 'foo' elements to 'bar' elements
    you simply add
    <xsl:template match="foo">
    <bar>
    <xsl:apply-templates select="@* | node()"/>
    </bar>
    </xsl:template>



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 6, 2008
    #2
    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. Ken Adams
    Replies:
    1
    Views:
    704
    Arnaud Berger
    Mar 10, 2005
  2. Bernd Fuhrmann
    Replies:
    0
    Views:
    438
    Bernd Fuhrmann
    Feb 12, 2004
  3. Jody Greening
    Replies:
    5
    Views:
    678
    Jody Greening
    Jan 6, 2005
  4. Jody Greening
    Replies:
    0
    Views:
    338
    Jody Greening
    Jan 6, 2005
  5. Replies:
    4
    Views:
    667
Loading...

Share This Page