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 April 10th, 2008, 09:07 AM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Default transforming types derived by extension?

I'm trying to generate a template which matches types derived by extension from a base type. A simple example (using types from the xml schema primer) would be a match that matches Address, any subtype of Address (such as USAddress and UKAddress), and any subtypes of the subtypes (etc.).

I'm working under the assumption that a XSLT2 schema-aware processor would be able to do this.

 
Old April 10th, 2008, 09:31 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I think you can use e.g.
Code:
<xsl:template match="schema-element(BaseTypeNameHere)">
Note that for types defined in a namespace you need e.g.
Code:
<xsl:template match="schema-element(prefix:BaseTypeNameHere)">
--
  Martin Honnen
  Microsoft MVP - XML
 
Old April 10th, 2008, 09:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, if you declare

<xsl:template match="element(*, address)">

then it will match any element whose type is address, or a type derived form address by restriction or extension.

Unfortunately the current Saxon release has a bug in its handling of this case, see:

https://sourceforge.net/tracker/inde...72&atid=397617

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 11th, 2008, 09:45 PM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Thanks, the use of element() worked for me. Interestingly, I had tries that previously without success. It appears that a validation error in my XSL file was causing that template to silently (no error or warning) not work and thus have the engine (AltovaXML) default to a non-schema-aware template. After re-checking (and fixing) my XSL everything worked. Knowing what the right answer was really helped.

 
Old April 12th, 2008, 06:50 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, I've noticed that behaviour in AltovaXML too. The same happens in Saxon, of course, if you simply forget to switch validation on for the input document. It's a good idea to write your stylesheet so there is a template rule for element(*, xs:untyped) that catches the fact that untyped data has been supplied, and throws an error.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
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
Not a ReportDocument derived class chokk Crystal Reports 0 May 10th, 2006 08:21 AM
Force Derived Method rodmcleay C# 7 June 1st, 2005 01:19 AM
Using reflection to get derived classes jaucourt VB.NET 2002/2003 Basics 0 May 10th, 2004 09:14 AM





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