473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 2248
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 same file. The master template calls an...
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) and display its output in a specific html tag,...
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 these products and then, give me your opinion about...
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 i.e. keys, extra colums etc.. In some cases I...
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 checkbox. i m using asp.net,vb.net pls help me we...
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 Register</name> <address>"00000000"</address>...
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 so that editing was very easy and less time...
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"> Is this implemented in Sablotron? It's quite...
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 displaying others as node 1 and node 2? This data is...
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 values, if there are 2 values per (row) Issuer I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.