Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2003, 01:47 PM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transform xml to xml changing one tag.

Hi,

I would like to transform an xml document only affecting text nodes. My problem is that I can't seem to get the attributes to show up in the output.

Here is my stylesheet, you can use any xml document against it just include some attributes to see that they do not come out in the output. I am looking for a generic approach such that I could use this stylesheet against any xml structure.

Thank you for any suggestions!!!

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>

<xsl:template match="title/text()">
hello there
</xsl:template>

<xsl:template match="*">
    <xsl:variable name="document">
        <xsl:apply-templates/>
    </xsl:variable>

    <xsl:element name="{name()}">
        <xsl:copy-of select="$document"/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>
 
Old October 29th, 2003, 01:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Hi,

you need an identity transformation making template plus "refined" template for text nodes. I also included xsl:strip-space to avoid whitespace-nodes (if you need also to change all the whitespace nodes, you can remove it).

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="text()">
        hello there
    </xsl:template>
</xsl:stylesheet>
Regards,
Armen
 
Old April 21st, 2010, 05:14 PM
Registered User
 
Join Date: Apr 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default attributes to nodes?

Is this supposed to convert attributes of an XML element to an XML node?

I.E. From:
Code:
<VehicleAttribute type="VehicleType" typeid="12" value="Truck" valueid="4673" />
To:
Code:
<VehicleAttribute>
<type>VehicleType</type>
<typeid>12</typeid>
<value>Truck</value>
<valueid>4673</valueid>
</VehicleAttribute>
(it doesn't seem to do anything. the above is what I'm looking for)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I transform XSLT without the <?xml?> tag? nadavvin XSLT 4 June 10th, 2007 09:25 AM
XML to XML transform (Simplified) nmahesh567 XSLT 2 March 24th, 2007 07:57 AM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM
Transform XML to XML using XSLT Mr.D XSLT 2 September 7th, 2004 02:13 PM
XML to (different <tag>) XML mapping Thodoris XML 4 April 27th, 2004 04:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.