xsl-list
[Top] [All Lists]

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

2008-02-13 07:30:21
Hi,

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

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
   Author: David
   File: normalisemddl.xsl
   Date: 20080212
   Purpose: Normalise MDDL derived schema to remove groups and children
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
   <xsl:output method="text" indent="yes" encoding="UTF-8"/>
   <xsl:template match="/">
       <xsl:choose>
         <xsl:when test="//xsd:group[ends-with(@ref, '.children')]">
<!-- We find the group element this refers to and write out the elements as a part of this complexType -->
           <xsl:variable name="elementName" select="@name"/>
<xsl:for-each select="/xsd:group/*[starts-with(@name, $elementName)]/child[1]/child">
             <xsl:attribute name="minOccurs">0</xsl:attribute>
             <xsl:attribute name="maxOccurs">1</xsl:attribute>
             <xsl:copy-of select="."/>
           </xsl:for-each>
         </xsl:when>
<xsl:when test="/xsd:group[ends-with(@name, '.children')]">
           <!-- Skip over this group, it is used by the match above -->
         </xsl:when>
<xsl:when test="/xsd:complexType[1] and child[1]::xsd:sequence and child[1]/child[1]::xsd:choice and child[1]/child[1]/(minOccurs='0') and child[1]/child[1]/(maxOccurs='unbounded')">
             <!-- 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]"/>
             </xsl:for-each>
         </xsl:when>
<xsl:otherwise>
           <!-- We emit this element unharmed -->
           <xsl:value-of select="." />
         </xsl:otherwise>
       </xsl:choose>
   </xsl:template>
</xsl:stylesheet>

what I want to do is
1. Remove any       <xsd:choice minOccurs="0" maxOccurs="unbounded">
and alter each of the elements that are children of this element to include minOccurs="0" maxOccurs="1" 2. Remove any <xsd:group that is referred to by a <xsd:group ... with a ref with a name ending with '.children' and pull in all the elements in that group in line where the original reference occured.
3. Emit everything else unharmed.

Here is an abbreviated content of the file I am trying to transform with examples of the contracts I am trying to alter.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="normalised.xslt"?>
<!-- Created with Liquid XML Studio 1.0.7.0 (http://www.liquid-technologies.com) --> <xsd:schema xmlns:xlink="http://www.w3.org/1999/xlink"; xmlns:gensec="http://www.stpenable.com/gensec"; attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.stpenable.com/gensec"; xmlns:xsd="http://www.w3.org/2001/XMLSchema";> <xsd:import schemaLocation="mddl-3.0-beta-link.xsd" namespace="http://www.w3.org/1999/xlink"; /> <xsd:import schemaLocation="xml.xsd" namespace="http://www.w3.org/XML/1998/namespace"; />

 <xsd:group name="Amortization.children">
   <xsd:choice>
     <xsd:element ref="gensec:amortizationBehavior" />
     <xsd:element ref="gensec:amortizationType" />
     <xsd:element ref="gensec:firstAmount" />
     <xsd:element ref="gensec:firstDate" />
     <xsd:element ref="gensec:lastAmount" />
     <xsd:element ref="gensec:lastDate" />
     <xsd:element ref="gensec:nextAmount" />
     <xsd:element ref="gensec:nextDate" />
     <xsd:element ref="gensec:nextPeriod" />
     <xsd:element ref="gensec:penultimateAmount" />
     <xsd:element ref="gensec:penultimateDate" />
     <xsd:element ref="gensec:period" />
     <xsd:element ref="gensec:schedule" />
   </xsd:choice>
 </xsd:group>
 <xsd:complexType name="Amortization">
   <xsd:sequence minOccurs="0" maxOccurs="1">
     <xsd:element ref="gensec:mdBoolean" />
<xsd:group minOccurs="0" maxOccurs="unbounded" ref="gensec:Amortization.children" />
     <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:source" />
     <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:other" />
   </xsd:sequence>
   <xsd:attribute name="id" type="xsd:ID" use="optional" />
<xsd:attribute default="valid" name="validity" type="gensec:QualityEnumeration" use="optional" />
 </xsd:complexType>
 <xsd:element name="amortization" type="gensec:Amortization" />

 <xsd:complexType name="PortfolioDomain">
   <xsd:sequence>
     <xsd:choice minOccurs="0" maxOccurs="unbounded">
       <xsd:element ref="gensec:industryIdentifier" />
       <xsd:element ref="gensec:instrumentIdentifier" />
       <xsd:element ref="gensec:issueData" />
       <xsd:element ref="gensec:underlying" />
       <xsd:element ref="gensec:underlyingCount" />
     </xsd:choice>
     <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:source" />
     <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:other" />
   </xsd:sequence>
   <xsd:attribute name="id" type="xsd:ID" use="optional" />
 </xsd:complexType>
 <xsd:element name="portfolioDomain" type="gensec:PortfolioDomain" />
</xsd:schema>

The error I get when opening in Firefox is "
XML Parsing Error: junk after document element
Location: file:///D:/DevProjects/mddlQuestFor/schemas/3.0-beta/mddl-3.0-test.xml
Line Number 7953, Column 14:</xsd:schema>g"

Which suggests to me I have not understood the output
-------------^

I also tried this

D:\DevProjects\mddlQuestFor\>java -cp ./xalan.jar;./xercesImpl.jar;./serializer.jar;./xmi-apis.jar org.apache.xalan.xslt.Process -I
l -XSL normalised.xslt -OUT test.xml
SystemId Unknown; Line #12; Column #70; Could not find function: ends-with
SystemId Unknown; Line #12; Column #70; function token not found.
(Location of error unknown)java.lang.NullPointerException
SystemId Unknown; Line #12; Column #70; Could not find function: ends-with
SystemId Unknown; Line #12; Column #70; function token not found.
(Location of error unknown)java.lang.NullPointerException
Xalan: was not successful.

So maybe my syntax is wrong, but I cannot see where.

Thx.

David





--~------------------------------------------------------------------
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>