Trying to display tagname

Here should go questions about transforming XML with XSLT and FOP.
lou_boumian
Posts: 7
Joined: Sat Nov 10, 2007 11:32 am
Location: Vancouver, BC

Trying to display tagname

Post by lou_boumian »

I am a translator, not a programmer, and I am completely new to this game.

I have several XML docs of the form:

Code: Select all

<content>
<checklist_c1>
<ENG>Confirmation</ENG>
<CHI></CHI>
<CHT></CHT>
<RUS></RUS>
<POL></POL>
<FIL></FIL>
<FRE></FRE>
<VIE></VIE>
<SPA></SPA>
<PER></PER>
<PAN></PAN>
<HIN></HIN>
</checklist_c1>
<checklist_c2>
<ENG>You need the following three pieces of information as proof you have completed this orientation. Please select one of the options below, then click the</ENG>
<CHI></CHI>
<CHT></CHT>
<RUS></RUS>
<POL></POL>
<FIL></FIL>
<FRE></FRE>
<VIE></VIE>
<SPA></SPA>
<PER></PER>
<PAN></PAN>
<HIN></HIN>
</checklist_c2>
....
</content>
Where I have to introduce the French translation of the English String (value of ENG) into the value of FRE.

I am trying to display these files as tables which will be much easier to handle.

I figured out how to display a table with 2 columns titled:
English and French
with the following XLS file:

Code: Select all


<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="node()">
<html>
<body>

<table border="2">
<tr>
<th>English</th>
<th>French</th>
</tr>
<xsl:for-each select="content/*">
<tr>
<td><xsl:value-of select="ENG" /></td>
<td><xsl:value-of select="FRE" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
But I would like to have a first column displaying the tagname of the first child :
checklist_c1, checklist_c2, etc...

I have tried with the following code :

Code: Select all


<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="node()">
<html>
<body>

<table border="2">
<tr>
<th>Entry #</th>
<th>English</th>
<th>French</th>
</tr>
<xsl:for-each select="content/*">
<tr>
<td><xsl:value-of select="name()" /></td>
<td><xsl:value-of select="ENG" /></td>
<td><xsl:value-of select="FRE" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
...but it does not work.

(I realize that I don't realy know what I am doing here...)

If anybody has a suggestion, that would help!

Thanks!

Pascal
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

Is content the first node in your xml source? What output are you getting right now?
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

Also you might want to change your xsl namespace to the standard one.
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

It really looks like your xslt should work otherwise.
lou_boumian
Posts: 7
Joined: Sat Nov 10, 2007 11:32 am
Location: Vancouver, BC

Post by lou_boumian »

Thanks for your suggestion jkmyoung.

When I use my xsl namespace version, I get this error:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Unknown method. -->name()<--
When I use your name space instead of mine, I get this error:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Required attribute 'version' is missing.
lou_boumian
Posts: 7
Joined: Sat Nov 10, 2007 11:32 am
Location: Vancouver, BC

Post by lou_boumian »

Is content the first node in your xml source?
Yes
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

You probably need version="1.0" in your stylesheet node.
lou_boumian
Posts: 7
Joined: Sat Nov 10, 2007 11:32 am
Location: Vancouver, BC

Post by lou_boumian »

You probably need version="1.0" in your stylesheet node.
How would you write the namespace then?
I tried <xmlns:xsl="http://www.w3.org/1999/XSL/Transform version="1.0"> and it gives me this error:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

A name contained an invalid character. Error processing resource 'file:///D:/checklist_FRE.xml
<xmlns:xsl="http://www.w3.org/1999/XSL/Transform version="1.0">
----------^
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
lou_boumian
Posts: 7
Joined: Sat Nov 10, 2007 11:32 am
Location: Vancouver, BC

Post by lou_boumian »

Thanks,
with this name space, I have no error but I just get this table:

-------------------------------------
| Entry # | English | French |
-------------------------------------
| Entry # | English | French |
-------------------------------------
lou_boumian
Posts: 7
Joined: Sat Nov 10, 2007 11:32 am
Location: Vancouver, BC

Post by lou_boumian »

So I have this xml file:

Code: Select all

<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="content.xsl"?>
<content>
<checklist_c1>
<ENG>Confirmation</ENG>
<CHI></CHI>
<CHT></CHT>
<RUS></RUS>
<POL></POL>
<FIL></FIL>
<FRE></FRE>
<VIE></VIE>
<SPA></SPA>
<PER></PER>
<PAN></PAN>
<HIN></HIN>
</checklist_c1>
<checklist_c2>
<ENG>You need the following three pieces of information as proof you have completed this orientation. Please select one of the options below, then click the</ENG>
<CHI></CHI>
<CHT></CHT>
<RUS></RUS>
<POL></POL>
<FIL></FIL>
<FRE></FRE>
<VIE></VIE>
<SPA></SPA>
<PER></PER>
<PAN></PAN>
<HIN></HIN>
</checklist_c2>
</content>
an this xsl file:

Code: Select all


<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()">
<html>
<body>

<table border="2">
<tr>
<th>Entry #</th>
<th>English</th>
<th>French</th>
</tr>
<xsl:for-each select="content/*">
<tr>
<td><xsl:value-of select="name()" /></td>
<td><xsl:value-of select="ENG" /></td>
<td><xsl:value-of select="FRE" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
and I only get the table shown in previous message:
-------------------------------------
| Entry # | English | French |
-------------------------------------
| Entry # | English | French |
-------------------------------------
instead of the desired result:

Code: Select all


---------------------------------------------------
| Entry # | English | French |
---------------------------------------------------
| checklist_c1 | Confirmation | |
---------------------------------------------------
| checklist_c2 | You need ...bla bla | |
---------------------------------------------------
I tried in IE7 Netscape 8. Same result for both.
Thanks jkmyoung for the tip about the namespace. Anybody else has a suggestion?
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

Change your template to:
<xsl:template match="/content">

And your for-each to:
<xsl:for-each select="*">
lou_boumian
Posts: 7
Joined: Sat Nov 10, 2007 11:32 am
Location: Vancouver, BC

Post by lou_boumian »

That works. Thanks a lot for your help jkmyoung !
Have a great day! :D
Post Reply