Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT: selecting a single sub-element to print

Reply
Thread Tools

XSLT: selecting a single sub-element to print

 
 
Tristan Miller
Guest
Posts: n/a
 
      02-08-2005
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
 
Reply With Quote
 
 
 
 
Mukul Gandhi
Guest
Posts: n/a
 
      02-08-2005
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 xmlnssl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xslutput 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>
<xsltherwise>
<xsl:value-of select="unicode/@value" />
<xsl:if test="position() != last()">
<xsl:text>&#xa;</xsl:text>
</xsl:if>
</xsltherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

Tristan Miller <> wrote in message news:<>...
> 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

 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      02-08-2005

> 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
 
Reply With Quote
 
Tristan Miller
Guest
Posts: n/a
 
      02-08-2005
Greetings.

In article <>, 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
 
Reply With Quote
 
David Carlisle
Guest
Posts: n/a
 
      02-09-2005

> 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
 
Reply With Quote
 
Tristan Miller
Guest
Posts: n/a
 
      02-09-2005
Greetings.

In article < >, 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Re: Selecting multiple fields, out of order, in a single Java XPathexpression Martin Honnen XML 0 07-18-2008 04:11 PM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
Selecting a single record from a dataset...help a newbie =?Utf-8?B?RCBMZWU=?= ASP .Net 2 11-19-2004 09:45 PM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57