xsl-list
[Top] [All Lists]

RE: [xsl] fairly complex xslt not giving errors I can understand

2008-02-13 10:47:35

I have the following to transform a XSD that is a standard 
for market data ( mddl.org)

There are many errors here beyond those that have been mentioned so far.

    <xsl:template match="/">
        <xsl:choose>
          <xsl:when test="//xsd:group[ends-with(@ref, '.children')]">
            <xsl:variable name="elementName" select="@name"/>

Your context node is the root (document) node. Document nodes don't have
attributes. I'm not sure which element's @name attribute you are after here.

            <xsl:for-each select="/xsd:group/*[starts-with(@name,
$elementName)]/child[1]/child">

/xsd:group selects an xsd:group element that's at the top-level of the
document. But the top-level element of your input document is always
xsd:schema. Also, xsd:group elements in a valid schema document can't have
children called "child". Perhaps you meant "*"?

              <xsl:attribute name="minOccurs">0</xsl:attribute>
              <xsl:attribute name="maxOccurs">1</xsl:attribute>

You've created two attributes, but you haven't yet created an element for
them to be attached to.

   
          <xsl:when test="/xsd:complexType[1] and 
child[1]::xsd:sequence

The outermost element will never be xsd:complexType

and child[1]/child[1]::xsd:choice and

This is made-up syntax, and I'm starting to have great trouble guessing what
you might mean by it. Perhaps child::*[1]/child::*[1][self::xsd:choice] -
but I'm guessing (like you are).
 
child[1]/child[1]/(minOccurs='0') and 
child[1]/child[1]/(maxOccurs='unbounded')">

I suspect these were meant to be predicates - so use [] rather than () - and
a predicate can't immediately follow a "/"

              <!-- Iterate thru all elements adding min=0 and 
max=1 -->
              <xsl:for-each select="./child[1]/child[1]">
                  <xsl:attribute name="minOccurs">0</xsl:attribute>
                  <xsl:attribute
name="maxOccurs">unbounded</xsl:attribute>
                  <xsl:copy-of select="./child[1]/child[1]"/>

It looks to me as if you are somehow imagining that you can add attributes
to elements in the source document. You can't. Remember that XSLT doesn't
modify the source - you are creating a result document, and if you want to
copy something, you have to do so explicitly.

You say yourself this is "fairly complex XSLT". I'd suggest you try to write
something simpler first - you're trying to run before you can walk.

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>