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

[xsl] Processing schema attributes with leading zeros?

Subject: [xsl] Processing schema attributes with leading zeros?
From: dvint@xxxxxxxxx
Date: Fri, 19 Oct 2012 08:49:13 -0700

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="."/>

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.


Current Thread