[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Simple XML transformation advice needed

Subject: [xsl] Simple XML transformation advice needed
From: Peter Dalmaris <Peter.P.Dalmaris@xxxxxxxxxx>
Date: Wed, 28 Jan 2004 14:52:46 +1100

Hello all,

I am a novice with XSLT and would appreciate any help in relation to a little problem I am having.

I have written a simple transformation XSL program that trasforms an XML document into a slightly different document, but I am having some trouble getting it right.

More details and the code is below.

Thank you,


What I am trying to get the template to do is to take something like this as input:

<ap:Text TextAlignment="urn:mindjet:Left" Dirty="0000000000000001" PlainText="Motivation, research problem and hypothesis 9">
<ap:Font Color="ff000000"/>

And produce this as output:

<ap:Text TextAlignment="urn:mindjet:Left" Dirty="0000000000000001">
<PlainText>Motivation, research problem and hypothesis 9</PlainText>
<ap:Font Color="ff000000"/>

Instead, it is producing this:

<ap:Text Dirty="0000000000000001">
<PlainText>Motivation, research problem and hypothesis 9</PlainText>
<ap:Font Color="ff000000"/>

In other words, I just want to take the PlainText attribute and create a new element with it, not affecting any of the other attributes.

Here is the code:

<!-- AttrToElement.xsl: Turn all attributes into subelements -->
<!-- Import the identity transformation. -->

<xsl:strip-space elements="*"/>

<xsl:output indent="yes"/>

<!-- Match any Attribute and turn it into an element -->

<xsl:template match="ap:Text/@PlainText">
<xsl:element name="{name(.)}"><xsl:value-of select="."/></xsl:element>

<xsl:template match="//cor:Base64">
        <xsl:element name="{name(.)}">

                <xsl:attribute name="xsi:nil"><xsl:value-of select="@xsi:nil" /></xsl:attribute>

                <xsl:attribute name="content"><xsl:value-of select="." /></xsl:attribute>



<xsl:template match="node()|@*">
<!-- Copy the current node -->

<!-- Including any attributes it has and any child nodes -->
<xsl:apply-templates select="@*|node()"/>



UTS CRICOS Provider Code:  00099F

This email message and any accompanying attachments may contain
confidential information.  If you are not the intended recipient, do not
read, use, disseminate, distribute or copy this message or attachments.
If you have received this message in error, please notify the sender
immediately and delete this message. Any views expressed in this message
are those of the individual sender, except where the sender expressly,
and with authority, states them to be the views the University of
Technology Sydney. Before opening any attachments, please check them for
viruses and defects.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread