xsl-list
[Top] [All Lists]

RE: Simple XML transformation advice needed

2004-01-28 03:00:29

If you want a php xml parser
http://talks.php.net/index.php/XML?PHPSESSID=ac77dab1a84022a39f4548a665e
91e36

/s


-----Original Message-----
From: Michael Kay [mailto:mhk(_at_)mhk(_dot_)me(_dot_)uk] 
Sent: 28 January 2004 10:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Simple XML transformation advice needed


The problem is that when you do:

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

it's not defined in what order the attributes will be processed. You are
required to generate attributes on the result element before you
generate child elements, so as you've discovered, your stylesheet will
work only if you choose an XML parser that happens to process the
attributes in the "right" order (for you), which is a matter of luck.

I'd suggest changing the apply-templates to control the order in which
attributes are processed explicitly.

Michael Kay
 

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Peter Dalmaris
Sent: 28 January 2004 03:53
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Simple XML transformation advice needed


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,

Peter
-----------------------------------------------
PROBLEM:

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"/> </ap:Text>

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"/> </ap:Text>

Instead, it is producing this:

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

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
--> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:cor="http://schemas.mindjet.com/MindManager/Core/2003";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:ap="http://schemas.mindjet.com/MindManager/Application/2003";
version="1.0"

<!-- 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>


<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:element>

</xsl:template>

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

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

</xsl:stylesheet>

-------------------------------



UTS CRICOS Provider Code:  00099F

DISCLAIMER
==============================================================
==========
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



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


______________________________________________________________
This message has been scanned for all viruses by BTnet VirusScreen. The
service is delivered in partnership with MessageLabs.

This service does not scan any password protected or encrypted
attachments.  

If you are interested in finding out more about the service, please
visit our website at
http://www.btignite.com/internetservices/btnet/products_virusscreen.htm
==============================================================

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



<Prev in Thread] Current Thread [Next in Thread>