Subject: RE: extrat value from current node only.
From: "emmanuel ide" <emmanuel@xxxxxxxxxxx>
Date: Wed, 30 Mar 2005 14:08:55 +0100
|
100% agree with you. I wish I could build the xml file myself. But trouble
is that we are using external xml file, don't have any control over the way
it is produced unfortunately.
-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: 30 March 2005 14:00
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: extrat value from current node only.
>
> Below are my xml & xls file:
One of the first things to learn with XSLT is to get your fingers around the
acronym...
>
> ________________ XML FILE _______________________
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <items>
> <item>
> title 1
> <description>description 1</description>
> </item>
> <item>
> title 2
> <description>description 2</description>
> </item>
> </items>
> _________________________________________________
>
Generally this isn't a good way of using XML mixed content (elements and
text nodes as siblings of each other). The normal use of mixed content is
for marking up parts of a continuous text, for example, <para>here is some
<emph>important</emph> text</para>. If it doesn't make sense to concatenate
the text with the adjacent elements, then the text should be in its own
element.
XSLT's value-of instruction assumes this design principle, because when you
take the value-of the <item> element, it concatenates all the contained
text.
You can get at "title 1" separately from the description element by
accessing the text nodes directly, but it's harder work.
Michael Kay
http://www.saxonica.com/
> ________________ XLS FILE _______________________
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="items">
> <xsl:apply-templates select="item"/>
> </xsl:template>
>
> <xsl:template match="item">
> title:<xsl:value-of select="current()"/>
> description:<xsl:value-of select="description"/>
> </xsl:template>
>
> </xsl:stylesheet> ___________________________________________________
>
> I don't get
> <?xml version="1.0" encoding="UTF-8"?>
> title:title 11
> description:description 1
>
> But ...
> <?xml version="1.0" encoding="UTF-8"?>
> title:
> title 1
> description 1
>
> description:description 1
> title:
> title 2
> description 2
>
> description:description 2
>
> What changes do I have to make to my xls file to get the
> output I want?
>
> Thank you for you help.
>
> Emmanuel
|