PHP - Is it possible to transform XML file to XSL file using xslt transformation -


i trying generate xsl file based on xml config file using xsl transformation.

here input.

<front>    <sample1/>    <sample2/>    <sample3>        <item1/>        <item2/>        <item3/>        <item4/>    </sample3>    <sample4/> </front> 

i expecting xsl file like,

<xsl:template match="//div[@class='front']">     <xsl:apply-templates select=".//*[@class='sample1']"/>     <xsl:apply-templates select=".//*[@class='sample2']"/>     <xsl:apply-templates select=".//*[@class='sample3']"/>     <xsl:apply-templates select=".//*[@class='sample4']"/> </xsl:template>  <xsl:template match="//*[@class='sample3']">     <xsl:apply-templates select=".//*[@class='item1']"/>     <xsl:apply-templates select=".//*[@class='item2']"/>     <xsl:apply-templates select=".//*[@class='item3']"/>     <xsl:apply-templates select=".//*[@class='item4']"/> </xsl:template>  

is can done using xsl transformation? main idea each , every time make changes in config file, no need write xsl file. should generated. if make changes like,

    <front>        <sample1/>        <sample2/>        <sample4/>        <sample3>            <item1/>            <item2/>            <item4/>            <item3/>        </sample3>     </front> 

the xsl should be,

<xsl:template match="//div[@class='front']">    <xsl:apply-templates select=".//*[@class='sample1']"/>    <xsl:apply-templates select=".//*[@class='sample2']"/>    <xsl:apply-templates select=".//*[@class='sample4']"/>    <xsl:apply-templates select=".//*[@class='sample3']"/> </xsl:template>     <xsl:template match="//*[@class='sample3']">    <xsl:apply-templates select=".//*[@class='item1']"/>    <xsl:apply-templates select=".//*[@class='item2']"/>    <xsl:apply-templates select=".//*[@class='item4']"/>    <xsl:apply-templates select=".//*[@class='item3']"/> </xsl:template> 

any appreciated. in advance!

there example of using xslt generate sttylesheet in xslt specification itself: https://www.w3.org/tr/xslt/#element-namespace-alias

try like:

xslt 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:axsl="http://www.w3.org/1999/xsl/transformalias"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>  <xsl:template match="/">     <axsl:stylesheet version="1.0">         <xsl:apply-templates/>     </axsl:stylesheet> </xsl:template>  <xsl:template match="/*">     <axsl:template match="div[@class='{name()}']">         <xsl:apply-templates mode="apply"/>     </axsl:template>     <xsl:apply-templates select="*[*]"/> </xsl:template>  <xsl:template match="*">     <axsl:template match="*[@class='{name()}']">         <xsl:apply-templates mode="apply"/>     </axsl:template>     <xsl:apply-templates select="*[*]"/> </xsl:template>  <xsl:template match="*" mode="apply">     <axsl:apply-templates select=".//*[@class='{name()}']"/> </xsl:template>  </xsl:stylesheet> 

note:

  1. a leading // entirely redundant in match pattern;

  2. are sure want have .// in xsl:apply-templates selectexpressions?


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -