XSL problem with numbers bigger than 100000
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 6
- Joined: Thu May 24, 2012 12:34 pm
XSL problem with numbers bigger than 100000
Hi,
I have a list of ranges to validate for overlap. E.g.:
Put together from a date range function I have the following XSL function to validate for overlap:
The functions seems to work fine if I run it on the data shown above. If I uncomment (1) it correctly tells that the ranges are overlapping. However whenever I have a range with number above 100000 the function return overlap even though that's not the case.
I'm wondering if I'm doing something wrong in the code or there's a bug in OxygenXML editor? (version 13.2)
Thanks in advance,
Bo
I have a list of ranges to validate for overlap. E.g.:
Code: Select all
<intervals>
<range start="10000" end="15000"/>
<range start="20000" end="25000"/>
<range start="80000" end="85000"/>
<range start="90000" end="95000"/>
<!-- (1) <range start="90000" end="95000"/> -->
<!-- (2) <range start="100000" end="105000"/> -->
</intervals>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:fct="http://custom"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="intervals">
<xsl:choose>
<xsl:when test="fct:check_overlap((),range)">No overlap</xsl:when>
<xsl:otherwise>Overlap!!</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="fct:check_overlap" as="xs:boolean">
<xsl:param name="current_end" as="xs:integer?"/>
<xsl:param name="ranges" as="node()*"/>
<xsl:choose>
<xsl:when test="not(exists($current_end))">
<xsl:variable name="orderedRanges" as="node()*">
<xsl:for-each select="$ranges">
<xsl:sort select="@start"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="fct:check_overlap(
xs:integer($orderedRanges[position()=1]/@end),
$orderedRanges[position()>1])"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="
if (not(exists($ranges))) then true() else
if ($current_end > $ranges[position()=1]/@start) then false() else
fct:check_overlap(
xs:integer($ranges[position()=1]/@end),
$ranges[position()>1])
"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
</xsl:stylesheet>
I'm wondering if I'm doing something wrong in the code or there's a bug in OxygenXML editor? (version 13.2)
Thanks in advance,
Bo
-
- Posts: 846
- Joined: Mon Dec 05, 2011 6:04 pm
Re: XSL problem with numbers bigger than 100000
Hello,
The cause of the incorrect result thrown by the "check_overlap" function is a sorting error that has crept in your code.
More specifically, when you sort the ranges (node sequences) by the "@start" attribute, the sorting is alphabetical, instead of numerical. So, in alphabetical terms, 100000 is lower than 95000 for example.
To achieve the desired results, the value of the "@start" attribute has to be cast to integer first.
For that, you should modiffy the line to
Regards,
Costin
The cause of the incorrect result thrown by the "check_overlap" function is a sorting error that has crept in your code.
More specifically, when you sort the ranges (node sequences) by the "@start" attribute, the sorting is alphabetical, instead of numerical. So, in alphabetical terms, 100000 is lower than 95000 for example.
To achieve the desired results, the value of the "@start" attribute has to be cast to integer first.
For that, you should modiffy the line
Code: Select all
<xsl:sort select="@start"/>
Code: Select all
<xsl:sort select="xs:integer(@start)"/>
Costin
Costin Sandoi
oXygen XML Editor and Author Support
oXygen XML Editor and Author Support
-
- Posts: 6
- Joined: Thu May 24, 2012 12:34 pm
Re: XSL problem with numbers bigger than 100000
Thanks for a quick reply!
That solved my problem (and found a similar conversion problem in another function
).
Is it possible to import custom XSL functions to a schematron file?
/Bo
That solved my problem (and found a similar conversion problem in another function

Is it possible to import custom XSL functions to a schematron file?
/Bo
-
- Posts: 846
- Joined: Mon Dec 05, 2011 6:04 pm
Re: XSL problem with numbers bigger than 100000
Hi again,
Yes, it is possible to use custom XSL functions in a schematron file.
For that, you should first check the "Allow foreign elements" option from oXygen Options > Preferences > XML > XML Parser.
To make a better idea, here is an example of using such a function:
The XML file:
The schematron file, with an example function:
Hope this helps.
Regards,
Costin
Yes, it is possible to use custom XSL functions in a schematron file.
For that, you should first check the "Allow foreign elements" option from oXygen Options > Preferences > XML > XML Parser.
To make a better idea, here is an example of using such a function:
The XML file:
Code: Select all
<?xml-model href="Test.sch" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<test>
</test>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" xmlns:x="http://www.example.com/x"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<ns uri="http://www.example.com/x" prefix="x"/>
<xsl:function name="x:f" >
<xsl:text>DATA FROM FUNCTION</xsl:text>
</xsl:function>
<pattern id="p1">
<rule context="test">
<assert test="false()">
Test function <value-of select="x:f()"/>
</assert>
</rule>
</pattern>
</schema>
Regards,
Costin
Costin Sandoi
oXygen XML Editor and Author Support
oXygen XML Editor and Author Support
-
- Posts: 6
- Joined: Thu May 24, 2012 12:34 pm
Re: XSL problem with numbers bigger than 100000
Thanks, I already got that far - what puzzles me is if I can put the xsl-function in a separate file? I'm already using the functions for some normal XSL stylesheets.
Best regards,
Bo
Best regards,
Bo
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XSL problem with numbers bigger than 100000
Hi,
You can put XSL functions (xsl:function) in a separate file and include it in schematron. Make sure that the included file contains only XSL functions. Specifically, make sure that this included file does not contain XSL templates or it might create a mess.
Regards,
Adrian
You can put XSL functions (xsl:function) in a separate file and include it in schematron. Make sure that the included file contains only XSL functions. Specifically, make sure that this included file does not contain XSL templates or it might create a mess.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 6
- Joined: Thu May 24, 2012 12:34 pm
Re: XSL problem with numbers bigger than 100000
Thanks, I had some trouble getting the include correct, but the following seems to work and get the namespace correct also:
Best regards,
Bo
Code: Select all
<xsl:include href="custom_fct.xsl"/>
<ns prefix="fct" uri="http://custom"/>
Bo
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service