xml - XSLT missing some tags -


i'm writing generic xsl stylesheet previewing xml in system, works fine, cases skips span.label , span.value markup.

so istance if there tag having children text - works. (a > b+c)

if there tag text on first level, output text content omitting tag name. ( a )

also if there tag has 1 child has several children text - omit first level tag name, show second level tag name , show text content third level. ( a > b > c + d + e)

here xslt:

<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">     <xsl:template match="/">     <html>     <head>     <title>preview</title>     <meta charset="utf-8" />         <style>               .level { line-heigth: 20px; }               .label { width: 150px; display:inline-block;                         background-color:#eee; margin-right:10px;                         margin-top:5px; padding:5px; vertical-align:top; }               .value { display:inline-block;  vertical-align:top;                         padding: 5px; margin-top:5px;}                    </style>     </head>     <body>         <div class='level'>                 <xsl:apply-templates />              </div>       </body>     </html>     </xsl:template>      <xsl:template match="*" >           <span class='label'><xsl:value-of select ="local-name(.)"/><xslt:text>:</xslt:text></span>         <span class='value'><xsl:value-of select="text()" /></span>         <xsl:if test="attribute::*">         <br />         <span class="label"> attributes:                         <xsl:number value="count(attribute::*)" format="1"/></span>         <span class="value">                       <xsl:for-each select="attribute::*">                <xsl:value-of select="local-name()" />                         <xslt:text> : </xslt:text>                         <xsl:value-of select="." />              </xsl:for-each>          </span>          </xsl:if>         <xsl:for-each select="*">             <div class='level'>                <xsl:apply-templates />             </div>         </xsl:for-each>         <br />     </xsl:template> </xsl:stylesheet> 

it's hard without sample input/output, think issue here:

    <xsl:for-each select="*">         <div class='level'>            <xsl:apply-templates />         </div>     </xsl:for-each> 

you're looping on each child element (select="*") , not outputting information it.

try removing xsl:for-each , doing <xsl:apply-templates select="*"/>. you'll have move div too.

maybe like:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">     <xsl:template match="/">         <html>             <head>                 <title>preview</title>                 <meta charset="utf-8" />                     <style>                     .level { line-heigth: 20px; }                     .label { width: 150px; display:inline-block;                      background-color:#eee; margin-right:10px;                      margin-top:5px; padding:5px; vertical-align:top; }                     .value { display:inline-block;  vertical-align:top;                      padding: 5px; margin-top:5px;}                                </style>             </head>             <body>                 <xsl:apply-templates />              </body>         </html>     </xsl:template>      <xsl:template match="*" >           <div class='level'>             <span class='label'><xsl:value-of select ="local-name(.)"/><xsl:text>:</xsl:text></span>             <span class='value'><xsl:value-of select="text()" /></span>             <xsl:if test="@*">                 <br />                 <span class="label"> attributes:                          <xsl:number value="count(@*)" format="1"/></span>                 <span class="value">                     <xsl:for-each select="@*">                            <xsl:value-of select="local-name()" />                         <xsl:text> : </xsl:text>                         <xsl:value-of select="." />                        </xsl:for-each>                 </span>             </xsl:if>             <br />             <xsl:apply-templates select="*"/>         </div>     </xsl:template> </xsl:stylesheet> 

(i replaced attribute:: axes abbreviated syntax @.)


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -