Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Begginer question: template for a data type [Thread Next] Re: Begginer question: template for a data typeTo: 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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
