Tuesday, June 13, 2017

XSLT 3.0 reaches W3C Recommendation status

Not long ago, XSLT 3.0 has reached the W3C Recommendation status. Below is the link to the XSLT 3.0 spec:

https://www.w3.org/TR/2017/REC-xslt-30-20170608/

XSLT 3.0 is a very advanced and useful language, as compared to XSLT 2.0. One of the main features (among others) introduced in XSLT 3.0, is that the XSLT transformation can be done in streaming mode.

3 comments:

Anton Udovychenko said...

Hello, I need your help. I have some part of xml:
Info
TextInf key="order_number" value="00353410"/
TextInf key="order_date" value="13.04.2017"/
TextInf key="sender" value="4660000941015"/
/Info
How to create xcd for this xml using version 1.1?

Mukul Gandhi said...

I assume, that your XML document is following:
<?xml version="1.0"?>
<Info>
<TextInf key="order_number" value="00353410"/>
<TextInf key="order_date" value="2017-04-13"/>
<TextInf key="sender" value="4660000941015"/>
</Info>

I've changed your date value to the ISO value, which XSD supports.

I think, you'd need a set of <assert> elements in XSD to model the validation constraints, something like following:
<pre>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Info">
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" minOccurs="3" maxOccurs="3"/>
</xs:sequence>
<xs:assert test="*[1]/self::TextInf"/>
<xs:assert test="*[2]/self::TextInf"/>
<xs:assert test="*[3]/self::TextInf"/>
<xs:assert test="not(*[1]/node() and *[2]/node() and *[3]/node())"/>
<xs:assert test="(*[1]/@key = 'order_number') and (*[1]/@value castable as xs:integer)"/>
<xs:assert test="(*[2]/@key = 'order_date') and (*[2]/@value castable as xs:date)"/>
<xs:assert test="(*[3]/@key = 'sender') and (*[3]/@value castable as xs:integer)"/>
<xs:assert test="count(*[1]/@*) = 2"/>
<xs:assert test="count(*[2]/@*) = 2"/>
<xs:assert test="count(*[3]/@*) = 2"/>
</xs:complexType>
</xs:element>

</xs:schema>
</pre>

Mukul Gandhi said...

You could have asked your question against this post, "XPath 2.0 atomization in XML Schema 1.1 validation" because that's related to XSD & its 1.1 version. This blog post is related to XSLT.

You wrote in your question, How to create xcd for this xml using version 1.1?. I assumed, that you meant XSD 1.1.

Thanks.