Match nodes inheriting from type in XSLT

Atheist

New Member
We have an XSD which defines the following:\[code\]<xsd:element name="Product" type="cm:Product" abstract="true" /><xsd:complexType name="Product" abstract="true"> <xsd:sequence> <xsd:element name="name" type="xsd:string" minOccurs="0" /> <!-- Other common elements --> </xsd:sequence></xsd:complexType><xsd:element name="Subscription" type="cm:Subscription" /><xsd:complexType name="Subscription"> <xsd:complexContent> <xsd:extension base="cm:Product"> <xsd:sequence> <!-- Subscription specific elements --> </xsd:sequence> </xsd:extension> </xsd:complexContent></xsd:complexType>\[/code\]I need to create an XSLT which takes the product name and a few other things and convert it into a web service request. The problem is that I don't really know if the top element actually says \[code\]cm:Product\[/code\], \[code\]cm:Subscription\[/code\] or something completely different (but which extends cm:Product).Is there a way I can somehow write a template which matches both \[code\]cm:Product\[/code\] elements and all elements extending \[code\]cm:Product\[/code\]?Simple example input\[code\]<Subscription xmlns="http://schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <name>Basis</name></Subscription>\[/code\]What I have so far\[code\]<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cm="http://schema" exclude-result-prefixes="cm"> <xsl:param name="processID" /> <xsl:template match="/"> <xsl:element name="RequestElement"> <xsl:element name="processId"> <xsl:value-of select="$processID" /> </xsl:element> <xsl:apply-templates /> </xsl:element> </xsl:template> <xsl:template match="cm:Product/cm:name"> <xsl:element name="name"> <xsl:value-of select="." /> </xsl:element> </xsl:template> <xsl:template match="text()" /></xsl:stylesheet>\[/code\]This works if I change \[code\]cm:Product\[/code\] to \[code\]cm:Subscription\[/code\], which is in my particular input xml, but the problem is that I can't know that it actually is a cm:Subscription. All I "know" is that it is an element extending \[code\]cm:Product\[/code\]
 
Back
Top