 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 29th, 2010, 10:12 AM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Newbie: Apparently Fine XSLT Generates No Output
Hi all,
I received an XSL file that someone wrote last summer, which to me appears to be operable. However, when I run a transformation, lo and behold, there is no output but the lines that declare the version of XSL.
I am very new to XSL, and would greatly appreciate if you could point out the errors that would cause this piece of code to not generate anything. Don't feel I'm asking you to re-write the entire thing for me; just point out the errors and I should be able to go from there.
Thank you so much in advance, and do let me know if you need more information. I can show an entry from the original XML file if needed for some context.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:processing-instruction name="oxygen">
RNGSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.rng"
type="xml" </xsl:processing-instruction>
<xsl:processing-instruction name="oxygen">
SCHSchema="http://lego-wordlists.googlecode.com/svn/trunk/linguistlist/linguist-lift-schemas/linguist-lift.sch"
</xsl:processing-instruction>
<lift>
<xsl:attribute name="version">
<xsl:text>0.13</xsl:text>
</xsl:attribute>
<xsl:for-each select="LEXICON/ENTRY">
<xsl:variable name="uid">
<xsl:value-of select="generate-id(.)"/><!-- Generating entry id appended with underscore at the beginning -->
</xsl:variable>
<entry>
<xsl:attribute name="id">
<xsl:value-of select="concat('_',$uid)"/>
</xsl:attribute>
<trait>
<xsl:attribute name="name">
<xsl:value-of select="'original-id'"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select=".//referenceid"/>
</xsl:attribute>
</trait>
<lexical-unit>
<form>
<xsl:attribute name="cng">
<xsl:value-of select="'lang'"/><!-- Treats the text within the <unanylyzedform> element as the actual word for each entry. -->
</xsl:attribute>
<text>
<xsl:value-of select=".//lexical-unit"/><!-- Treats the text within the <unanylyzedform> element as the actual word for each entry. -->
</text>
</form>
</lexical-unit>
<sense>
<grammatical-info>
<xsl:attribute name="value">
</xsl:attribute>
</grammatical-info>
<definition>
<form>
<xsl:attribute name="lang">
<xsl:value-of select="'cmn'"/><!-- Treats the text within the <gloss-MandarinChinese> element as the actual word for each entry.
'cmn'-code for the MandarinChinese language-->
</xsl:attribute>
<text>
<xsl:value-of select=".//gloss-MandarinChinese"/>
</text>
</form>
<form>
<xsl:attribute name="lang">
<xsl:value-of select="'eng'"/><!-- Treats the text within the <gloss-MandarinChinese> element as the actual word for each entry.
'cng'-code for the other languages-->
</xsl:attribute>
<text>
<xsl:value-of select=".//gloss-english"/>
</text>
</form>
</definition>
</sense>
</entry>
</xsl:for-each>
</lift>
</xsl:template>
<xsl:template match="*">
<xsl:copy-of select="self::node()"/>
</xsl:template>
</xsl:stylesheet>
|
|

July 29th, 2010, 10:17 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
The reason you are getting no output is... err, who knows.
It might be something to do with your input XML not matching the XSLT, but seeing as you haven't shown us any of your input XML it's hard to say.
|
|

July 29th, 2010, 10:17 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Well that stylesheet has a template matching "/", the root node, document node, and that template outputs processing instructions and a "lift" literal result element in any case so that should appear in the output, unless an initial context node other than a document node is set.
So which XSLT processor do you use, how do you run the transformation, how do you look at the result where you think there is no output?
And yes, post a piece of the XML input you are running the XSLT against.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

July 29th, 2010, 11:12 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
If you get no output from this XSLT then you are running it incorrectly. The XSLT code itself looks fine.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

July 29th, 2010, 12:36 PM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here are two sample entries:
Code:
<LIFT>
<LEXICON>
<lexical-unit>æ</lexical-unit>
<referenceid>3037</referenceid>
<crefid>2600019</crefid>
<gloss-MandarinChinese>yi</gloss-MandarinChinese>
<gloss-english>one</gloss-english>
</LEXICON>
<LEXICON>
<lexical-unit>æ</lexical-unit>
<referenceid>3065</referenceid>
<crefid></crefid>
<gloss-MandarinChinese>yi hao</gloss-MandarinChinese>
<gloss-english>the first day of a month</gloss-english>
</LEXICON>
Just note that the <LIFT> tag is closed at the end of all the entries, which are called lexical units (tagged <LEXICON> here).
|
|

July 29th, 2010, 12:43 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
How do you run that stylesheet exactly? It should output something the way it is coded, independent of the XML input.
However then it has xsl:for-each select="LEXICON/ENTRY" in a template matching "/", that does not fit the XML you posted as that has no ENTRY elements at all.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

July 29th, 2010, 12:55 PM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The LEXICON/ENTRY thing is something I noticed; when I changed it to just LEXICON, it still outputted nothing.
I'm using Oxygen 9.3 to do it - it has a thing where you set up a 'Transformation Scenario', specifying the input XML and the XSL file. I've done transformations exactly in this fashion before and had no difficulties.
|
|

July 29th, 2010, 12:56 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
It looks like the for each loop should be <xsl:for-each select="LIFT/LEXICON"> rather than LEXICON/ENTRY.
Also, there are many short cuts to a lot of the XSLT you have written. For example the following produces the identical XML output to what you have above:
Code:
...
<entry id="{concat('_',generate-id(.))}">
<trait name="original-id" value="{referenceid}"/>
<lexical-unit>
<form cng="lang">
<text>
<xsl:value-of select="lexical-unit"/>
</text>
</form>
</lexical-unit>
<sense>
<grammatical-info value=""/>
<definition>
<form lang="cmn">
<text>
<xsl:value-of select="gloss-MandarinChinese"/>
</text>
</form>
<form lang="eng">
<text>
<xsl:value-of select="gloss-english"/>
</text>
</form>
</definition>
</sense>
</entry>
...
Note the use of the {} inside an attribute to calculate an XPath expression, as well as replacing ".//X" with "X" which will be a lot faster and cleaner.
|
|

July 30th, 2010, 09:41 AM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you, SamJudson!
That was exactly what was needed.
|
|
 |