XPath2 and format-number() - "function ... not available wi

Questions about XML that are not covered by the other forums should go here.
pwpw
Posts: 5
Joined: Sat Dec 11, 2010 8:55 pm

XPath2 and format-number() - "function ... not available wi

Post by pwpw » Wed Dec 15, 2010 2:44 pm

Hello List:

I am wanting to execute an XPath2 expression and format the numbers returned as strings with leading zeros. I expected to be able to use the function 'format-number()' but although that function is available in the oXygen XPath2 autocompleter list of functions when I execute the XPath I get an error stating that "System function format-number() is not available with this host language."

Grateful for guidance here

Thanks
Pete

adrian
Posts: 2659
Joined: Tue May 17, 2005 4:01 pm

Re: XPath2 and format-number() - "function ... not available wi

Post by adrian » Wed Dec 15, 2010 6:18 pm

Hello,

"format-number()" shouldn't be shown in the XPath content completion list since it's an XSLT 2.0 function and not an XPath 2.0 function. So this is a mistake on our part for listing it there in the first place.
I've added this to our issue tracking tool and we will address it in a future version of Oxygen.

The only workaround I see here to use this function is to create an XSLT 2.0 stylesheet and use this function in an <xsl:value-of select="">.

Regards,
Adrian

Edit: I forgot to mention the link to the specification:
http://www.w3.org/TR/xslt20/#function-format-number
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

pwpw
Posts: 5
Joined: Sat Dec 11, 2010 8:55 pm

Re: XPath2 and format-number() - "function ... not available wi

Post by pwpw » Sun Dec 19, 2010 12:40 am

HI Adrian
Thanks for the help.

Is it possible to use a (parameterised?) XSLT within a Schematron "assert" or "report" element? If so, can you perhaps illustrate how this is done.

Many thanks

Pete

george
Site Admin
Posts: 2102
Joined: Thu Jan 09, 2003 2:58 pm

Re: XPath2 and format-number() - "function ... not available wi

Post by george » Tue Dec 28, 2010 6:16 pm

Hi Pete,

I am afraid I do not understand exactly your question. Please provide some more details and eventually also a usecase.

In Schematron it is possible to include XSLT code, even XSLT function if you use @queryBinding="xslt2" and turn on "Allow foreign elements" from Options->Preferences -- XML / XML Parser -- ISO Schematron.

ISO Schematron also has support for abstract patterns that you can then instantiate with different parameters.

Best Regards,
George
George Cristian Bina

pwpw
Posts: 5
Joined: Sat Dec 11, 2010 8:55 pm

Re: XPath2 and format-number() - "function ... not available wi

Post by pwpw » Fri Dec 31, 2010 6:33 pm

Hi George

in a bit of XML such as

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<root>
<record id="1">
<doc>
<id>001</id>
<content>some content</content>
</doc>
<doc>
<id>002</id>
<content>some content</content>
</doc>
<doc>
<id>003</id>
<content>some content</content>
</doc>
<doc>
<id>004</id>
<content>some content</content>
</doc>
<doc>
<id>005</id>
<content>some content</content>
</doc>
</record>
<record id="2">
<doc>
<id>001</id>
<content>some content</content>
</doc>
<doc>
<id>002</id>
<content>some content</content>
</doc>
<doc>
<id>005</id>
<content>some content</content>
</doc>
</record>
</root>
I want to set up a Schematron test to check that the doc/id values within each record are in a continuous sequence - 001, 002, 003 etc

I was hoping to use something like (for the context <record>

Code: Select all

for $a in ( 1 to count(doc)) return $a
to generate a sequence, but wanted to return the sequence padded to a pattern, in this case to a field width of 3 with leading zeroes. This was where I was thinking of using the xsl:format-number() function.

I'd appreciate list members' views.

Thanks

Pete

george
Site Admin
Posts: 2102
Joined: Thu Jan 09, 2003 2:58 pm

Re: XPath2 and format-number() - "function ... not available wi

Post by george » Mon Jan 03, 2011 12:32 pm

You can use a Schematron schema like:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern id="testSequence">
<rule context="record/doc/id">
<let name="p" value="count(../preceding-sibling::doc) + 1"/>
<assert test="number(.)=$p">
The id should have the value <value-of select="$p"/>!
</assert>
<assert test="string-length(.)=3">
The id should have 3 digits (ddd), from 001 to 999.
</assert>
</rule>
</pattern>
</schema>
Best Regards,
George
George Cristian Bina

Post Reply