xml - Change Node name of an XSLT based on an include file -


hi have xslt file need transform xml file.

sample xslt

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:template match="/">     <document>       <customer>         <header>           <message>             <xsl:value-of select="//header/message"/>           </message>        </header>      </customer>     </document>   </xsl:template>   <xsl:include href="inc1.xsl" /> </xsl:stylesheet>  

now need change node name customer supplier depending on include filename @ bottom , 1 more thing, have specific attributes document node depending on include file.

thanks , hope can me out.

the viable mechanism have included stylesheet handle specific element names , <document> attributes: this:

<?xml version="1.0"?> <xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform">      <xsl:template match="/">         <document>             <xsl:call-template name="apply-document-attributes" />             <xsl:element name="{$customer-element-name}">                 <header>                     <message>                         <xsl:value-of select="//header/message" />                     </message>                 </header>             </xsl:element>         </document>     </xsl:template>      <xsl:include href="inc1.xsl" />  </xsl:stylesheet>  

and included stylesheet:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform">      <xsl:variable name="customer-element-name" select="'supplier'"/>      <xsl:template name="apply-document-attributes">         <xsl:attribute name="foo">bar</xsl:attribute>     </xsl:template> </xsl:stylesheet> 

or,

<xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform">      <xsl:variable name="customer-element-name" select="'customer'"/>      <xsl:template name="apply-document-attributes"/> </xsl:stylesheet> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -