[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Processing schema attributes with leading zeros?

Subject: Re: [xsl] Processing schema attributes with leading zeros?
From: Dan Vint <dvint@xxxxxxxxx>
Date: Fri, 19 Oct 2012 16:22:50 -0700

Thanks this is the s1000d schema and I was surprised by the result. I have some other 01 values in other attributes that I believe came through fine. Based upon the answer, I will have to look, but my guess is that they are declared as strings.

This wasn't schema aware transformation, but it was schema aware validation that caught the bad result.


At 09:36 AM 10/19/2012, you wrote:
Presumably it's a schema-aware transformation, in which case the typed value of the month attribute is the integer 6. When you do select="." to construct the new attribute, the effect is to select the old attribute and atomize it, which gives the integer 6, and then to convert the result to a string, which gives you the string "6".

You might do better with select="string(.)", which should give you the string value of the old attribute node; but processors are allowed to reconstruct the string value from the typed value if they choose.

Basically, by typing this attribute as an integer, you are saying that leading zeroes aren't significant, which contradicts what you are implying in your question, which is that they are significant.

The use of an XSD pattern to constrain a value to something other than its canonical lexical form is always problematic with schema-aware XSLT and XQuery. There's no way the processor can try to construct a representation of an integer that matches a supplied pattern; regular expressions just don't work that way.

Michael Kay

On 19/10/2012 16:49, dvint@xxxxxxxxx wrote:
I have the following elemnt content:
       <issdate year="2012" month="06" day="15"/>

When I process it with the following templates I get this result:
       <issueDate year="2012" month="6" day="15"/>

I'm trying to understand is why the leading 0 on the month was stripped.

The schema has this definition:
     <xs:element name="issdate" type="issdateType"/>
     <xs:complexType name="issdateType">
         <xs:attributeGroup ref="DATE"/>
     <xs:attributeGroup name="DATE">
         <xs:attribute ref="year" use="required"/>
         <xs:attribute ref="month" use="required"/>
         <xs:attribute ref="day" use="required"/>
     <xs:attribute name="year" type="YEAR"/>
     <xs:simpleType name="YEAR">
         <xs:restriction base="xs:gYear">
             <xs:pattern value="\d{4}"/>
     <xs:attribute name="month" type="MONTH"/>
     <xs:simpleType name="MONTH">
         <xs:restriction base="xs:positiveInteger">
             <xs:maxInclusive value="12"/>
             <xs:pattern value="\d{2}"/>
     <xs:attribute name="day" type="DAY"/>
     <xs:simpleType name="DAY">
         <xs:restriction base="xs:positiveInteger">
             <xs:maxInclusive value="31"/>
             <xs:pattern value="\d{2}"/>

This is processed with a template that has this:

<xsl:template mathc="issdate">

<!-- code to map old names to new names and set $newName removed, in this
     issdate is mapped to issueDate

<xsl:element name="{$newName}">
<xsl:call-template name="processAttributes"/>


<xsl:template name="prosessAttributes"> <xsl:for-each select="@*"> <!-- code to rename attributes removed --> <xsl:attribute name="{name()}" select="."/> </xsl:for-each> </xsl:template>

So basically my code is renaming the element and then just copying the
attribute values through for this particular element. Why am I loosing the
leading 0? I'd really like to avoid having to know what the content might
be in all casses for attributes.


--------------------------------------------------------------------------- Danny Vint

Panoramic Photography

voice: 619-938-3610

Current Thread