you can see xml patern sample below. every manuel has chapter tags, chapter tags may have subchapter , checklist tags. there no static depth, may change document document, couldnt write dynamic recursive xslt code generate html. knows, how can achive this.
<manuel name="test"> <chapter name="00"> <subchapter name="00.01"> <checklist name="00.01.01"> <summary>abc</summary> </checklist> </subchapter> <subchapter name="00.02"> <checklist name="00.02.01"> <summary>def</summary> </checklist> <subchapter name="00.02.02"> <checklist name="00.02.02.01"> <summary>xyz</summary> </checklist> </subchapter> </subchapter> <checklist name="00.03"> <summary>zzzz</summary> </checklist> </chapter> </manuel>
for sample, suppose result. can set css style, not important now. problem generating structure.
<div class="csschapter"> 00</div> <div class="csssubchapter"> 00.01 </div> <div class="csschecklist"> 00.01.01 </div> <div class="csssummary"> abc </div> <div class="csssubchapter"> 00.02 </div> <div class="csschecklist"> 00.02.01 </div> <div class="csssummary"> def </div> <div class="csssubchapter"> 00.02.02 </div> <div class="csschecklist"> 00.02.02.01 </div> <div class="csssummary"> xyz </div> <div class="csschecklist"> 00.03 </div> <div class="csssummary"> zzzz</div>
use simple apply-templates:
<?xml version="1.0" encoding="utf-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:template match="manuel"> <xsl:apply-templates select=".//*"/> </xsl:template> <xsl:template match="chapter"> <div class="csschapter"> <xsl:value-of select="@name"/> </div> </xsl:template> <xsl:template match="subchapter"> <div class="csssubchapter"> <xsl:value-of select="@name"/> </div> </xsl:template> <xsl:template match="checklist"> <div class="csschecklist"> <xsl:value-of select="@name"/> </div> </xsl:template> <xsl:template match="summary"> <div class="csssummary"> <xsl:value-of select="."/> </div> </xsl:template> </xsl:transform>
online @ http://xsltransform.net/3nj3915/1.
Comments
Post a Comment