XSLT: how to process whole document??

Discussion in 'XML' started by Bartek, Jul 7, 2004.

  1. Bartek

    Bartek Guest

    Hello

    This is my problem:
    It consider xml 2 xml conversion.
    source document had unknown structure (xhtml),
    xslt must process every node, attribute, text, comments etc. from source and
    write in destination file.
    During that process i must catch some nodes (e.g. <input> position of this
    node in XML tree is unknown )and change the value attribute.
    The destination xml file must be the exact copy of source file + changes on
    value attribute on some nodes.

    Where can i find some sample code that can process and write whole context
    node by node, comment etc.

    thanks for any help
     
    Bartek, Jul 7, 2004
    #1
    1. Advertising

  2. Bartek wrote:


    > It consider xml 2 xml conversion.
    > source document had unknown structure (xhtml),
    > xslt must process every node, attribute, text, comments etc. from source and
    > write in destination file.
    > During that process i must catch some nodes (e.g. <input> position of this
    > node in XML tree is unknown )and change the value attribute.
    > The destination xml file must be the exact copy of source file + changes on
    > value attribute on some nodes.
    >
    > Where can i find some sample code that can process and write whole context
    > node by node, comment etc.


    Start with the identity transformation as described here:
    http://www.w3.org/TR/xslt#copying
    then add templates for those elements you need to change, here is a
    simple example, the XHTML is

    <?xml version="1.0" encoding="UTF-8"?>
    <html
    xmlns="http://www.w3.org/1999/xhtml"
    lang="en" xml:lang="en">
    <head>
    <title>example document to be transformed</title>
    </head>
    <body>
    <form action="whatever.php">
    <fieldset>
    <legend>Who is GOD?</legend>
    <label>
    Who is GOD?
    <input type="text" name="GOD" value="???" />
    </label>
    <input type="submit" />
    </fieldset>
    </form>
    </body>
    </html>

    the XSLT is

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

    <xsl:eek:utput method="xml" encoding="UTF-8" />

    <xsl:template match="@* | node()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
    </xsl:template>

    <xsl:template
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    match="xhtml:input[@name = 'GOD']">
    <xsl:copy>
    <xsl:apply-templates select="@*[local-name() != 'value']" />
    <xsl:attribute name="value"><xsl:text>Kibo</xsl:text></xsl:attribute>
    </xsl:copy>
    </xsl:template>

    </xsl:stylesheet>

    the XHTML output is

    <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <title>example document to be transformed</title>
    </head>
    <body>
    <form action="whatever.php">
    <fieldset>
    <legend>Who is GOD?</legend>
    <label>
    Who is GOD?
    <input type="text" name="GOD" value="Kibo"/>
    </label>
    <input type="submit"/>
    </fieldset>
    </form>
    </body>
    </html>

    so the value attribute has been changed.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jul 7, 2004
    #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. Matthieu Gaillet
    Replies:
    2
    Views:
    351
    Jukka K. Korpela
    Apr 5, 2004
  2. Hari Prakash
    Replies:
    1
    Views:
    374
    Martin Honnen
    Jul 16, 2004
  3. Replies:
    3
    Views:
    1,829
  4. Replies:
    4
    Views:
    716
  5. \A_Michigan_User\
    Replies:
    2
    Views:
    942
    \A_Michigan_User\
    Aug 21, 2006
Loading...

Share This Page