472,333 Members | 1,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

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 2183
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Keith Chadwick | last post by:
I have a fairly hefty XSLT file that for the sake of debugging and clarity I wish to split into some separate sub-templates contained within the...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind)...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the...
0
by: Terry Brown | last post by:
I have an xml file: <?xml version="1.0" encoding="utf-8" ?> <G2Registers xmlns="http://tempuri.org/registers.xsd"> <register> <name>Version...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML...
4
by: gouranga | last post by:
Sablotron keeps giving an error (non-XSL instruction) on the line with this code: <xsl:result-document href="slideshow/index.html" format="html">...
15
by: Jeff Uchtman | last post by:
Can I draw from 2 XML sources, the structure is exactly the same execpt for data contained into 1 xslt using math to add some structrure, and...
1
by: balderdash | last post by:
Hi I am very close to achieving the output I need but I cant seem to get it right. The problem is I am looping through a table and selecting...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.