Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Begginer question: template for a data type

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 4/11/2006 2:38:00 PM



George Bina wrote:

> You can do that with a schema aware XSLT 2.0 processor like Saxon 8 SA
> from Saxonica for instance. See below a working sample.

George is right, XSLT 1.0/XPath 1.0 is not schema aware at all so using 
an XSLT 2.0 schema aware processor is one solution.
However MSXML 4 and later and .NET 2.0 XslCompiledTransform while 
implementing XSLT/XPath 1.0 provide some extension functions to access 
schema type information so with those processors you could do the 
following (using the same schema George has posted):

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:ms="urn:schemas-microsoft-com:xslt"
   exclude-result-prefixes="ms">


   <xsl:template match="/">
     <result><xsl:apply-templates/></result>
   </xsl:template>

   <!-- Match on any element that has the type person -->
   <xsl:template match="*[ms:type-is('', 'person')]">
     <xsl:copy-of select="."></xsl:copy-of>
   </xsl:template>

</xsl:stylesheet>

Now you need to make sure when the XML is parsed that the schema is 
known, one easy way to do that is to use xsi:noNamespaceSchemaLocation e.g.

<?xml version="1.0" encoding="UTF-8"?>
<test
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="test.xsd">
   <father>
     <name>test1</name>
   </father>
   <mother>
     <name>test2</name>
   </mother>
</test>

See the MSXML documentation on using those extension functions here
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/b1643c25-3f62-4f97-b00a-38026a75db0d.asp>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/f1c46829-7149-4957-b789-220b5a0b38ae.asp>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent