Pages

Tuesday, July 13, 2010

Create XSLT from XSLT

The below XSLT can be used to create a XSLT from a requirementXML.

 

KEY XML File

 

<doc>

<xpath-group><xpath>/catalog</xpath></XPATH-GROUP>

<xpath-group><xpath>/catalog/cd</xpath></XPATH-GROUP>

</doc>

 

XSLT FILE

 

<?xml:namespace prefix = xsl /><xsl:stylesheetversion="2.0" xsl="http://www.w3.org/1999/XSL/Transform"axsl="http://www.w3.org/1999/XSL/Transform/alias">

<xsl:variablename="XpLocCat"></xsl:variable>

<xsl:output method="xml"></xsl:output>

 

<xsl:namespace-aliasprefix="xsl"></xsl:namespace-alias>

 

 

<xsl:template match="/">

 

<?xml:namespace prefix = axsl /><axsl:stylesheetversion="2.0"xsl="http://www.w3.org/1999/XSL/Transform">

 

<axsl:outputmethod="xml"></axsl:output>

 

<axsl:template match="*  @*">

<axsl:copy>

<axsl:apply-templatesselect="@*"></axsl:apply-templates>

<axsl:apply-templates></axsl:apply-templates>

</axsl:copy>

</axsl:template>

<xsl:apply-templates></xsl:apply-templates>

</axsl:stylesheet>

 

</xsl:template>

 

<xsl:template match="/Doc">

<xsl:for-each select="/Doc/Xpath-Group">

<axsl:template match="{Xpath}">

<xsl:element name="{XpathNew}">

<axsl:apply-templatesselect="@*"></axsl:apply-templates>

<xsl:if test="XpathCon!=''">

<axsl:apply-templatesselect="{XpathCon}"></axsl:apply-templates>

</xsl:if>

<xsl:if test="XpathCon=''">

<axsl:apply-templates></axsl:apply-templates>

</xsl:if>

</xsl:element>

</axsl:template>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

No comments: