[z3-checkins] r10731 - z3/clarity/trunk/xslt

faassen at codespeak.net faassen at codespeak.net
Sat Apr 16 15:22:29 MEST 2005


Author: faassen
Date: Sat Apr 16 15:22:29 2005
New Revision: 10731

Modified:
   z3/clarity/trunk/xslt/clarity.xsl
Log:
Add support for attributes, but I'm not exactly happy:

* it's not possible to output <? and ?> as attribute values,
  which means that ClearSilver won't recognize them. I created an
  unescape.xsl which I'll check in shortly which fixes this in a
  second stage of the pipe, but it's a mess.

* XPath has severely limited whitespace handling abilities. Right now
  we split on "; ", but that doesn't catch multi line attribute definitions.
  I want to split on ";", but that means any sequence spelled
  "foo bar; hoi dag" will result in an attribute with the name
  " hoi" being created, with an initial space. This is illegal.
  And I can't find a simple strip whitespace functionality in XPath!

At this rate it will be easier to implement all this behavior in
Python, though that would suck for other reasons.



Modified: z3/clarity/trunk/xslt/clarity.xsl
==============================================================================
--- z3/clarity/trunk/xslt/clarity.xsl	(original)
+++ z3/clarity/trunk/xslt/clarity.xsl	Sat Apr 16 15:22:29 2005
@@ -33,6 +33,40 @@
     </xsl:choose>
   </xsl:template>
 
+  <xsl:template match="@cs:attributes">
+    <xsl:call-template name="attribute">
+      <xsl:with-param name="attr" select="."/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template name="attribute">
+    <xsl:param name="attr"/>
+    <xsl:choose>
+      <xsl:when test="contains($attr,';')">
+	<xsl:call-template name="attribute">
+	  <xsl:with-param name="attr" select="substring-after($attr,'; ')"/>
+	</xsl:call-template>
+	<xsl:call-template name="output_attribute">
+	  <xsl:with-param name="segment" select="substring-before($attr, '; ')" />
+	</xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+	<xsl:call-template name="output_attribute">
+	  <xsl:with-param name="segment" select="$attr"/>
+	</xsl:call-template>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template name="output_attribute">
+    <xsl:param name="segment"/>
+    <xsl:variable name="name" select="substring-before($segment, ' ')"/>
+    <xsl:variable name="value" select="substring-after($segment, ' ')"/>
+    <xsl:attribute name="{$name}">
+      <xsl:text disable-output-escaping="yes">&lt;?cs var:html_escape</xsl:text>(<xsl:value-of disable-output-escaping="yes" select="$value"/>)<xsl:text disable-output-escaping="yes">?&gt;</xsl:text>
+    </xsl:attribute>    
+  </xsl:template>
+  
   <xsl:template match="@*">
     <xsl:if test="namespace-uri() != 'http://namespaces.zope.org/clearsilver'">
       <xsl:copy-of select="."/>


More information about the z3-checkins mailing list