Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2009, 04:03 PM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Default Problem in Matching XML Derived Types

Hello,
I had been under the impression that tests for things like "element(*, jsw:x)" would match when the current node was either of type jsw:x or derived from it. However, in at least one example (using SaxonSA 9.1.0.6), this doesn't seem to be working for me. Any advice as to what I am doing wrong? (details follow below.)
Thanks in advance.
Regards,
John

I'm expecting output of:
Code:
rootelem is NOT of type jsw:x.
A is of type jsw:x.
B is of type jsw:x.
C is NOT of type jsw:x.
But seeing output of:
Code:
rootelem is of type jsw:x.
A is NOT of type jsw:x.
B is NOT of type jsw:x.
C is NOT of type jsw:x.
My XSL is:
[code]
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jsw="http://www.company.com/whelan"
xmlns:fn="http://www.w3.org/2005/xpath-functions" >
<xsl:output method="text" indent="yes" encoding="UTF-8" />
<xsl:param name="input_parameter" />
<xsl:import-schema schema-location="file:///D:/JSW/sandbox/StringForSubtype/input.xsd"
namespace="
 
Old December 9th, 2009, 04:06 PM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Default

I seem to be unable to post the whole example. I'll look to add it ane part at a time...

The XSD for my input is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.company.com/whelan" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.company.com/whelan">
  <xs:complexType name="w">
   <xs:sequence>
    <xs:element ref="A"/>
    <xs:element ref="B"/>
    <xs:element ref="C"/>
   </xs:sequence>
  </xs:complexType>  
 <xs:element name="rootelem" type="w"/>
 <xs:element name="A" type="x"/>
 <xs:element name="B" type="y"/>
 <xs:element name="C" type="z"/>
 <xs:simpleType name="x">
  <xs:restriction base="xs:string"/>
 </xs:simpleType>
 <xs:simpleType name="y">
  <xs:restriction base="x"/>
 </xs:simpleType>
 <xs:simpleType name="z">
  <xs:restriction base="xs:string"/>
 </xs:simpleType>
</xs:schema>
 
Old December 9th, 2009, 04:07 PM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Default

My input XML is:
Code:
 
<?xml version="1.0"?>
<rootelem xmlns="http://www.company.com/whelan" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.company.com/whelan D:\JSW\sandbox\StringForSubtype\input.xsd"><A/><B/><C/></rootelem>
 
Old December 9th, 2009, 04:13 PM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Default

My XSL is:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jsw="http://www.company.com/whelan"
xmlns:fn="http://www.w3.org/2005/xpath-functions" >
<xsl:output method="text" indent="yes" encoding="UTF-8" />
<xsl:param name="input_parameter" /> 
<xsl:import-schema schema-location="file:///D:/JSW/sandbox/StringForSubtype/input.xsd"
 
namespace="http://www.company.com/whelan"/>
  <xsl:template match="/">
    <xsl:apply-templates select="node()"/>
  </xsl:template>
  <xsl:template match="node()">
      <xsl:choose>
        <xsl:when test="element(*, jsw:x)">
          <xsl:value-of select="name(.)"/><xsl:text> is of type jsw:x.</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="name(.)"/><xsl:text> is NOT of type jsw:x.</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
         <xsl:text>
</xsl:text>
    <xsl:apply-templates/>
  </xsl:template>
</xsl:stylesheet>
 
Old December 9th, 2009, 06:55 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your test test="element(*, jsw:x)" is equivalent to test="child::element(*, jsw:x)" - it tests whether the context item has a child of that type, not whether it is itself of that type. You want test=". instance of element(*, jsw:x)", or test="self::element(*, jsw:x)".
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
whelanj (February 2nd, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Derived Interfaces synack C# 2008 aka C# 3.0 1 October 31st, 2009 05:36 AM
A programming problem for Data Types code_lover Intro Programming 1 May 13th, 2008 06:42 AM
transforming types derived by extension? whelanj XSLT 4 April 12th, 2008 06:50 AM
Derived Field debbiecoates Beginning VB 6 2 February 20th, 2008 06:58 AM
Problem transforming unbounded types. amac XSLT 3 July 8th, 2006 04:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.