XSLT: small changes to xml from XPath

Discussion in 'XML' started by Karsten, Sep 14, 2007.

  1. Karsten

    Karsten Guest

    Hello

    How do I copy most of a xml file, but change a few attributes and/or
    elements based on a xpath?
    How do I make the xslt file?


    I know this description isn't much, but here is a small example

    <root>
    ...
    <element atr="value"/>
    ...
    </root>

    to

    <root>
    ...
    <element atr="*new value*"/>
    ...
    </root>
    Karsten, Sep 14, 2007
    #1
    1. Advertising

  2. Karsten wrote:
    > How do I copy most of a xml file, but change a few attributes and/or
    > elements based on a xpath?
    > How do I make the xslt file?


    Start with the XSLT "Identity Transform" -- which you can get from the
    XSLT spec or from any good XSLT tutorial.

    Write an additional template which recognizes the node you want to
    alter, and which constructs the new result.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Sep 14, 2007
    #2
    1. Advertising

  3. Karsten

    George Bina Guest

    Like below:

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

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

    <xsl:template match="element">
    <xsl:copy>
    <xsl:attribute name="atr">*new value*</xsl:attribute>
    <xsl:apply-templates select="node|@*[not(name()='atr')]"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina - http://aboutxml.blogspot.com/
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com
    George Bina, Sep 15, 2007
    #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. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,958
    jan V
    Jul 29, 2005
  2. Stylus Studio
    Replies:
    0
    Views:
    516
    Stylus Studio
    Oct 5, 2004
  3. Replies:
    3
    Views:
    271
    Vircom
    Sep 24, 2007
  4. Mark Space

    Small language changes

    Mark Space, Mar 3, 2009, in forum: Java
    Replies:
    23
    Views:
    703
    Wojtek
    Mar 5, 2009
  5. Yannick

    ASP changes Big JPG -> Small JPG

    Yannick, Feb 2, 2004, in forum: ASP General
    Replies:
    6
    Views:
    147
    Tim Williams
    Feb 3, 2004
Loading...

Share This Page