[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Processing schema attributes with leading zeros?
Subject: Re: 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.
..dan
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
Saxonica
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:complexType>
<xs:attributeGroup name="DATE">
<xs:attribute ref="year" use="required"/>
<xs:attribute ref="month" use="required"/>
<xs:attribute ref="day" use="required"/>
</xs:attributeGroup>
<xs:attribute name="year" type="YEAR"/>
<xs:simpleType name="YEAR">
<xs:restriction base="xs:gYear">
<xs:pattern value="\d{4}"/>
</xs:restriction>
</xs:simpleType>
<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:restriction>
</xs:simpleType>
<xs:attribute name="day" type="DAY"/>
<xs:simpleType name="DAY">
<xs:restriction base="xs:positiveInteger">
<xs:maxInclusive value="31"/>
<xs:pattern value="\d{2}"/>
</xs:restriction>
</xs:simpleType>
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
case
issdate is mapped to issueDate
-->
<xsl:element name="{$newName}">
<xsl:call-template name="processAttributes"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<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.
..dan
---------------------------------------------------------------------------
Danny Vint
Panoramic Photography
http://www.dvint.com
voice: 619-938-3610
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|