469,358 Members | 1,659 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

XSLT: selecting a single sub-element to print

Greetings.

I have an XML file listing various information about text glyphs (Unicode
value, HTML entity name, SGML entity name, etc.). All glyphs have a
Unicode value, but not all of them have HTML or SGML entity names.

I want to print out a list of these glyphs, using the HTML entity name if
it is available; otherwise the Unicode value should be printed. The
trouble is that I don't know how I can print only one or the other.

Each glyph is represented by an element <char>. Inside is a set of 0 or
more <entity> elements with "set" attributes. If a glyph has an HTML
entity, then it will contain an <entity> with the "set" attribute
beginning with the characters "html". All <char> elements also contain
the Unicode value in the enclosed <unicode> element.

For example, I want the output of the following XML file to be as follows:

bar
2004
fred
2006

Can anyone help?

<char>
<entity name="foo" set="iso-8879-pub">...</entity>
<entity name="bar" set="html4-special">...</entity>
<unicode value="2003">...</unicode>
</char>

<char>
<entity name="baz" set="iso-8879-pub">...</entity>
<unicode value="2004">...</unicode>
</char>

<char>
<entity name="fred" set="html4-alpha">...</entity>
<entity name="quux" set="iso-8879-pub">...</entity>
<unicode value="2005">...</unicode>
</char>

<char>
<unicode value="2006">...</unicode>
</char>

Kind regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Jul 20 '05 #1
5 2106
Hi Tristan,
Assuming the XML is -

<?xml version="1.0"?>
<root>
<char>
<entity name="foo" set="iso-8879-pub">...</entity>
<entity name="bar" set="html4-special">...</entity>
<unicode value="2003">...</unicode>
</char>
<char>
<entity name="baz" set="iso-8879-pub">...</entity>
<unicode value="2004">...</unicode>
</char>
<char>
<entity name="fred" set="html4-alpha">...</entity>
<entity name="quux" set="iso-8879-pub">...</entity>
<unicode value="2005">...</unicode>
</char>
<char>
<unicode value="2006">...</unicode>
</char>
</root>

(Please note the use of additional <root> tag)

Please try this XSL -

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

<xsl:output method="text" />

<xsl:template match="/root">
<xsl:for-each select="char">
<xsl:choose>
<xsl:when test="entity[starts-with(@set,'html')]">
<xsl:value-of select="entity/@name" />
<xsl:if test="position() != last()">
<xsl:text>&#xa;</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="unicode/@value" />
<xsl:if test="position() != last()">
<xsl:text>&#xa;</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

Tristan Miller <ps********@nothingisreal.com> wrote in message news:<16****************@ID-187157.News.Individual.NET>...
Greetings.

I have an XML file listing various information about text glyphs (Unicode
value, HTML entity name, SGML entity name, etc.). All glyphs have a
Unicode value, but not all of them have HTML or SGML entity names.

I want to print out a list of these glyphs, using the HTML entity name if
it is available; otherwise the Unicode value should be printed. The
trouble is that I don't know how I can print only one or the other.

Each glyph is represented by an element <char>. Inside is a set of 0 or
more <entity> elements with "set" attributes. If a glyph has an HTML
entity, then it will contain an <entity> with the "set" attribute
beginning with the characters "html". All <char> elements also contain
the Unicode value in the enclosed <unicode> element.

For example, I want the output of the following XML file to be as follows:

bar
2004
fred
2006

Can anyone help?

<char>
<entity name="foo" set="iso-8879-pub">...</entity>
<entity name="bar" set="html4-special">...</entity>
<unicode value="2003">...</unicode>
</char>

<char>
<entity name="baz" set="iso-8879-pub">...</entity>
<unicode value="2004">...</unicode>
</char>

<char>
<entity name="fred" set="html4-alpha">...</entity>
<entity name="quux" set="iso-8879-pub">...</entity>
<unicode value="2005">...</unicode>
</char>

<char>
<unicode value="2006">...</unicode>
</char>

Kind regards,
Tristan

Jul 20 '05 #2
I have an XML file listing various information about text glyphs (Unicode
value, HTML entity name, SGML entity name, etc.)

You might also be interested in

http://www.w3.org/2003/entities/xml/unicode.xml

which is essentially the same sort of file. The XSLT files in
http://www.w3.org/2003/entities/xml
generate various HTML, DTD, XSLT2 character maps, and other documents from
that source.

David
Jul 20 '05 #3
Greetings.

In article <yg*************@penguin.nag.co.uk>, David Carlisle wrote:
I have an XML file listing various information about text glyphs
(Unicode value, HTML entity name, SGML entity name, etc.)

You might also be interested in

http://www.w3.org/2003/entities/xml/unicode.xml

which is essentially the same sort of file. The XSLT files in
http://www.w3.org/2003/entities/xml
generate various HTML, DTD, XSLT2 character maps, and other documents
from that source.


Actually, I'm using the file at <http://www.bitjungle.com/~isoent/> because
I need the LaTeX equivalents. The example I posted was a
simplification. :)

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Jul 20 '05 #4
Actually, I'm using the file at <http://www.bitjungle.com/~isoent/> because
I need the LaTeX equivalents. The example I posted was a
simplification. :)


Thre are latex equivalents in unicode.xml as well (sebastian and I have
a rather long latex connection:-) although actually the latex mapping
hasn't kept quite up to date with the unicode 3.x and 4 additions that
have been made to the file. The same will be true for the bitjungle file
though as I don't think it's been updated for Unicode 3 at all (eg it
doesn't list the Unicode slots for the bold and script math alphabets in
plane 1 as far as I can see.

However I didn't mean that you should necessarily switch source file,
just that the xslt files on the W3C site probably have examples of
whatever XSLT you need as the basic structure is broadly similar.

David
Jul 20 '05 #5
Greetings.

In article <b1**************************@posting.google.com >, Mukul Gandhi
wrote:
Please try this XSL -


Many thanks; your example did exactly what I wanted. The difference
between your code and what I was trying was the entity[...] syntax in the
<xsl:when> test attribute.

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Keith Chadwick | last post: by
reply views Thread by Christopher M. Lauer | last post: by
3 posts views Thread by Teksure | last post: by
6 posts views Thread by aaj | last post: by
reply views Thread by Terry Brown | last post: by
1 post views Thread by Nick | last post: by
4 posts views Thread by gouranga | last post: by
15 posts views Thread by Jeff Uchtman | last post: by
1 post views Thread by balderdash | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.