You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ne...@apache.org on 2007/04/25 15:53:27 UTC

svn commit: r532353 - in /lenya/trunk/src/modules/prettyprinting: ./ config/ config/module.xml xslt/ xslt/xml2nicexml.xsl

Author: nettings
Date: Wed Apr 25 06:53:24 2007
New Revision: 532353

URL: http://svn.apache.org/viewvc?view=rev&rev=532353
Log:
consolidated xml prettyprinting in new module. no functional changes.


Added:
    lenya/trunk/src/modules/prettyprinting/
    lenya/trunk/src/modules/prettyprinting/config/
    lenya/trunk/src/modules/prettyprinting/config/module.xml   (with props)
    lenya/trunk/src/modules/prettyprinting/xslt/
    lenya/trunk/src/modules/prettyprinting/xslt/xml2nicexml.xsl   (with props)

Added: lenya/trunk/src/modules/prettyprinting/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/prettyprinting/config/module.xml?view=auto&rev=532353
==============================================================================
--- lenya/trunk/src/modules/prettyprinting/config/module.xml (added)
+++ lenya/trunk/src/modules/prettyprinting/config/module.xml Wed Apr 25 06:53:24 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- $Id: publication.xml 374687 2006-02-03 15:24:55Z michi $ -->
+
+<module xmlns="http://apache.org/lenya/module/1.0">
+  <id>org.apache.lenya.modules.prettyprinting</id>
+  <package>org.apache.lenya.modules</package>
+  <version>0.2</version>
+  <name>XML pretty-printing</name>
+  <lenya-version>@lenya.version@</lenya-version>
+  <description>This module contains an XML pretty printing stylesheet that
+  will behave correctly wrt whitespace in XHTML.</description>
+</module>

Propchange: lenya/trunk/src/modules/prettyprinting/config/module.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lenya/trunk/src/modules/prettyprinting/xslt/xml2nicexml.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/prettyprinting/xslt/xml2nicexml.xsl?view=auto&rev=532353
==============================================================================
--- lenya/trunk/src/modules/prettyprinting/xslt/xml2nicexml.xsl (added)
+++ lenya/trunk/src/modules/prettyprinting/xslt/xml2nicexml.xsl Wed Apr 25 06:53:24 2007
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 
+   xml prettyprinter for apache cocoon/lenya, contributed by <ne...@apache.org>
+   everything that is non-trivial in this script has been borrowed from somewhere.
+   this script is in the public domain.
+-->
+
+<xsl:stylesheet version="1.0"
+      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="xml"/>
+
+<xsl:param name="indent-increment" select="'  '" />
+
+  <!-- 
+    indentation
+    thanks to John Mongan, taken from http://www.dpawson.co.uk/xsl/sect2/pretty.html
+  -->
+
+  <xsl:template match="*">
+    <xsl:param name="indent" select="'&#xA;'"/>
+
+    <xsl:value-of select="$indent"/>
+
+    <xsl:copy>
+      <xsl:copy-of select="@*" />
+      <xsl:apply-templates>
+        <xsl:with-param name="indent" select="concat($indent, $indent-increment)"/>
+      </xsl:apply-templates>
+      <!-- add a trailing newline if the node has children and is not a mixed content node -->
+      <xsl:if test="* and not(*[../text()[normalize-space(.) != '']])">
+        <xsl:value-of select="$indent"/>
+      </xsl:if>
+    </xsl:copy>
+   </xsl:template>
+
+   <xsl:template match="comment()|processing-instruction()">
+      <xsl:copy />
+   </xsl:template>
+
+  <!-- 
+    mixed content detection and handling
+    thanks to David Carlisle and Wendell Piez, taken from http://www.dpawson.co.uk/xsl/sect2/normalise.html#d7206e52 
+  -->
+  <xsl:template match="*[../text()[normalize-space(.) != '']]">
+    <!-- but this template matches any element appearing in mixed content -->
+    <xsl:variable name="textbefore"
+         select="preceding-sibling::node()[1][self::text()]"/>
+    <xsl:variable name="textafter"
+         select="following-sibling::node()[1][self::text()]"/>
+    <!-- Either of the preceding variables will be an empty node set 
+         if the neighbor node is not text(), right? -->
+    <xsl:variable name="prevchar"
+         select="substring($textbefore, string-length($textbefore))"/>
+    <xsl:variable name="nextchar"
+         select="substring($textafter, 1, 1)"/>
+  
+    <!-- Now the action: -->
+    <xsl:if test="$prevchar != normalize-space($prevchar)">
+    <!-- If the original text had a space before, add one back -->
+      <xsl:text> </xsl:text>
+    </xsl:if>
+  
+    <xsl:copy>
+    <!-- Copy the element over -->
+      <xsl:copy-of select="@*"/>
+      <xsl:apply-templates/>
+    </xsl:copy>
+  
+    <xsl:if test="$nextchar != normalize-space($nextchar)">
+    <!-- If the original text had a space after, add one back -->
+      <xsl:text> </xsl:text>
+    </xsl:if>
+  
+  </xsl:template>
+
+<!--
+  normalize all whitespace in text nodes (i.e. those that don't get matched by the mixed content handler)
+-->
+  <xsl:template match="text()">
+    <xsl:value-of select="normalize-space(.)"/>
+  </xsl:template>
+
+</xsl:stylesheet>

Propchange: lenya/trunk/src/modules/prettyprinting/xslt/xml2nicexml.xsl
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org