This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: indent XML doc based on spaces?



One more thing. 

XSLScript is using modified version of Nicolai's intentation
stylesheet. I was not happy with 

<element> text
</element>

I wanted it to be:  <element> text </element> , so I added one 
'if' statement to Nicolai's stylesheet and now it could be used to 
pretty-print xsl stylesheets.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output method="xml"/>
   <xsl:param select="'   '" name="indent-increment"/>
   
   <xsl:template match="*" name="noname">
      <xsl:param select="'&#xA;'" name="indent"/>
      <xsl:value-of select="$indent"/>
      <xsl:if test="name()='xsl:template'">
         <xsl:value-of select="$indent"/>
      </xsl:if>
      <xsl:copy>
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates>
            <xsl:with-param select="concat($indent, $indent-increment)" name="indent"/>
         </xsl:apply-templates>
         <xsl:if test="./* ">
            <xsl:value-of select="$indent"/>
         </xsl:if>
      </xsl:copy>
   </xsl:template>
   
   <xsl:template match="comment()|processing-instruction()">
      <xsl:copy/>
   </xsl:template>
   
   <xsl:template match="text()[normalize-space(.)='']"/>
</xsl:stylesheet>

Rgds.Paul.

Actually:

X:stylesheet {

X:output method="xml"
X:param indent-increment="'   '";

X:template noname(indent="'&#xA;'") = "*" {
 !{$indent}

 X:if "name()='xsl:template'" {
  !{$indent}
 }

 X:copy {
    X:copy-of "@*"
         !!( indent = "concat($indent, $indent-increment)" );
    X:if "./* " { !{$indent}  }
 }
}

 
X:template = "comment()|processing-instruction()" {
    X:copy;
}

X:template ="text()[normalize-space(.)='']" {}

}



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]