0
votes

I am trying to transform xml to html. With oxygen the Xpath such as follows:

<a href="#cite{count(preceding::citation) + 1}">
    <xsl:value-of select="count(preceding::citation) + 1"/>
</a>

Basically the purpose of this is to insert a numbered reference link, based on count of references preceeding.

This works when transformed in oxygen.

When run from command line, 1 is the output for all links.

command line commands Ive attempted look like this:

java  -jar /usr/share/java/saxon9he.jar -s:report1.xml -xsl:test.xsl -o:output4.html -t

I have also tried saxon9ee:

java -cp /usr/share/java/saxon9ee.jar com.saxonica.Transform -s:report1.xml -xsl:test.xsl -o:output3.html -t

Any help is appreciated!

test.xsl can be found here
http://pastebin.com/6qZeEgD8
report1.xml
http://pastebin.com/5SMY8c7W
contentconfig.xml
http://pastebin.com/A2etm4Cr

Here is the -t output:

 Saxon-HE 9.7.0.4J from Saxonica
 Java version 1.7.0_79
 Stylesheet compilation time:    1.59928s (1599.280903ms)
 Processing file:/root /CRIReportProject/cpreport.xml
 Using parser  com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
 Building tree for file:/root/CRIReportProject/cpreport.xml using   class net.sf.saxon.tree.tiny.TinyBuilder
 Tree built in 1.296529ms
 Tree size: 27 nodes, 54 characters, 5 attributes
 URIResolver.resolve href="contentconfig.xml" base="file:/root/CRIReportProject/cptest.xsl"
 Building tree for file:/root/CRIReportProject/contentconfig.xml using class net.sf.saxon.tree.tiny.TinyBuilder
 Tree built in 3.144498ms
 Tree size: 28 nodes, 161 characters, 6 attributes
 Execution time: 131.347609ms

Memory used: 8428592

1
Could be a namespace issue, Saxon's far more likely to be handling that correctly. Does your source have any namespace declaration that your citation element might belong to? - Flynn1179
Can you post minimal but complete samples to allow us to reproduce the problem? Which version of Saxon 9 is that exactly, what does -t show? - Martin Honnen
Also, research the xsl:number instruction. Difficult to say for sure, but it might be helpful as an alternative to counting preceding nodes, which isn't particularly efficient for large documents. - Flynn1179
In future please post your code in the body of the question, not on an external site. Such links tend to go dead, leaving an orphaned question on StackOverflow. - Michael Kay

1 Answers

1
votes

You are executing count(preceding::citation) in the template rule with match="method", and the context item for the evaluation is a <method> element in document report1.xml. This document contains no <citation> elements, so it is entirely reasonable that count(preceding::citation) should return zero. Your surrounding <xsl:if> takes a look in the other document contentconfig.xml, but it doesn't change the context to that document. Perhaps the xsl:if should be changed to an xsl:for-each, but then you need to make other changes as well, because the code is also looking for elements such as sup/a/@id which don't exist in either source document.

I have no idea why this code should behave differently in oXygen.

And by the way, if you do change the xsl:if to xsl:for-each, then you can probably change count(preceding::citation)+1 to position(), which will be much more efficient.