[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: fairly complex xslt not giving errors I can under

Subject: RE: fairly complex xslt not giving errors I can understand
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Wed, 13 Feb 2008 10:55:23 -0600
RE:  fairly complex xslt not giving errors I can  under
The error is actually not complex at all. If you look at the error's
line number and source code:
Line Number 7953, Column 14:</xsd:schema>g"
-----------------------------------------^

There's just a typo in the XML. Could be either in the source
(mddl-3.0-test.xml) or in the output from the transformation. In either
case, just look for a stray "g" character, and delete it.

As far as your Xalan error goes, ends-with() is a function from XPath
2.0, not present in XPath 1.0. The workaround is fairly simple, change:
  ends-with(@ref, '.children')
to:
  substring(@ref, string-length(@ref) - 8) = '.children'

Hope that helps.

~ Scott


-----Original Message-----
From: David at roamware [mailto:david@xxxxxxxxxxxxxx]
Sent: Wednesday, February 13, 2008 8:30 AM
To: Xsl-List
Subject:  fairly complex xslt not giving errors I can understand

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.