Skip to content

Commit

Permalink
structure stylesheet:
Browse files Browse the repository at this point in the history
* working on namespace stuff -- can now handle both when xslt is default namespace and when there's no default namespace (any other default namespace breaks stuff, I think)
  • Loading branch information
bwrobinett committed Nov 2, 2009
1 parent 02f22ea commit 68dfe2e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
20 changes: 14 additions & 6 deletions Bent/structure stylesheet/expample_doc.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xxx.xsl"?>
<html xmlns:ding="ding">
<html xmlns:ding="ding" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>bent</title>
<link rel="stylesheet" type="xml/sss" href="structure_stylesheet_example_alt2.xml"/>
</head>
<body>
<ding:blah></ding:blah>
<ding:blah/>
<p id="xxxxxxxxx">string 0</p>
<ul id="ding" class="blah" title="hello">
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ul>
<p><span id="dong" class="blah foo">string 2</span></p>
<p><span id="doh" class="blah">string 3</span></p>
<p><span>string 4</span></p>
<div><p>string 5</p></div>
<p>
<span id="dong" class="blah foo">string 2</span>
</p>
<p>
<span id="doh" class="blah">string 3</span>
</p>
<p>
<span>string 4</span>
</p>
<div>
<p>string 5</p>
</div>
</body>
</html>
12 changes: 9 additions & 3 deletions Bent/structure stylesheet/sss_compile2.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
<xsl:key name="struc_by_name" match="s:structure_stylesheet/s:struc" use="@name"/>
<xsl:variable name="s_namsepace_uri" select="namespace-uri(/*)"/>
<xsl:variable name="default_ns_is_xhtml" select="'http://www.w3.org/1999/xhtml' = /*/namespace::*[not(name())]"/>

<!--
Identity transform (what comes in goes out)
-->
Expand All @@ -26,8 +28,8 @@
</xsl:template>

<xsl:template match="s:structure_stylesheet">
<axsl:stylesheet version="1.0">
<xsl:copy-of select="namespace::*"/>
<axsl:stylesheet version="1.0" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="s xhtml">
<xsl:copy-of select="namespace::*|@*"/>
<axsl:output method="html" encoding="ISO-8859-1"/>
<axsl:template match="@*|node()">
<axsl:copy>
Expand Down Expand Up @@ -94,7 +96,11 @@
</xsl:if>

<!--create an xsl template for each match rule-->
<axsl:template match="{$tag}{$id}{$classes}{$attrs}" priority="{$selector_priority}">
<xsl:variable name="pre" select="substring-before($tag, ':')"/>
<xsl:variable name="maybe_pre">
<xsl:if test="not($pre) and $default_ns_is_xhtml">xhtml:</xsl:if>
</xsl:variable>
<axsl:template match="{$maybe_pre}{$tag}{$id}{$classes}{$attrs}" priority="{$selector_priority}">
<xsl:if test="$mode_id">
<xsl:attribute name="mode">
<xsl:value-of select="$mode_id"/>
Expand Down
6 changes: 4 additions & 2 deletions Bent/structure stylesheet/sss_ex2.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<s:structure_stylesheet xmlns:s="structure_stylesheet" xmlns:ding="ding">
<s:structure_stylesheet
xmlns:s="structure_stylesheet" xmlns:ding="ding" xmlns="http://www.w3.org/1999/xhtml"
>
<!--structures-->
<s:struc name="a">
<div class="wrapper">
<h1>before list</h1>
<h1>before list</h1>
<s:elem>
<s:class name="blah"/>
<s:class name="ding"/>
Expand Down
33 changes: 16 additions & 17 deletions Bent/structure stylesheet/xxx.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<html xmlns:ding="ding">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<html xmlns:ding="ding" xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>bent</title>
<link rel="stylesheet" type="xml/sss" href="structure_stylesheet_example_alt2.xml">
<link rel="stylesheet" type="xml/sss" href="structure_stylesheet_example_alt2.xml"></link>
</head>
<body>
<h1><span>(xxx)</span></h1>
<p id="xxxxxxxxx">string 0</p>
<div xmlns:s="structure_stylesheet" class="wrapper">
<h1>before list</h1>
<ol id="ding" class="blah ding hey what" title="THIS IS A TITLE">
<h2>prepend</h2>
<div class="innerwrap">
<div class="wrapper"><h1>before list</h1><ol id="ding" class="blah ding hey what" title="THIS IS A TITLE"><h2>prepend</h2><div class="innerwrap">
<li title="ding" class="hey foo hello"><h1 style="color:lightblue;">one</h1></li>
<li title="ding" class="hey foo hello"><h1 style="color:lightblue;">two</h1></li>
<li title="ding" class="hey foo hello"><h1 style="color:lightblue;">three</h1></li>
<li title="ding" class="hey foo hello"><h1 style="color:lightblue;">four</h1></li>
</div><h2>append</h2></ol><h1>after list</h1></div>
<p>
<span id="dong" class="blah foo">string 2</span>
</p>
<p>
<span id="doh" class="blah">string 3</span>
</p>
<p>
<span>string 4</span>
</p>
<div>
<p>string 5</p>
</div>
<h2>append</h2>
</ol>
<h1>after list</h1>
</div>
<p><span id="dong" class="blah foo">string 2</span></p>
<p><span id="doh" class="blah">string 3</span></p>
<p><span>string 4</span></p>
<div><p>string 5</p></div>
</body>
</html>
2 changes: 1 addition & 1 deletion Bent/structure stylesheet/xxx.xsl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0"?>
<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform" xmlns:ding="ding" xmlns:s="structure_stylesheet" version="1.0"><axsl:output method="html" encoding="ISO-8859-1"/><axsl:template match="@*|node()"><axsl:copy><axsl:apply-templates select="@*|node()"/></axsl:copy></axsl:template><axsl:template match="ul[@id = 'ding'][contains(concat(normalize-space(@class), ' '), 'blah ')]" priority="11011"><div class="wrapper"><h1>before list</h1><axsl:element name="ol"><axsl:apply-templates select="@*"/><axsl:attribute name="title">THIS IS A TITLE</axsl:attribute><axsl:variable name="orig_classes" select="concat(normalize-space(@class), ' ')"/><axsl:variable name="classes"><axsl:value-of select="$orig_classes"/><axsl:if test="not(contains($orig_classes, 'blah '))">blah </axsl:if><axsl:if test="not(contains($orig_classes, 'ding '))">ding </axsl:if><axsl:if test="not(contains($orig_classes, 'hey '))">hey </axsl:if><axsl:if test="not(contains($orig_classes, 'what '))">what </axsl:if></axsl:variable><axsl:variable name="trimmed_classes" select="normalize-space($classes)"/><axsl:if test="$trimmed_classes"><axsl:attribute name="class"><axsl:value-of select="$trimmed_classes"/></axsl:attribute></axsl:if><h2>prepend</h2><div class="innerwrap"><axsl:apply-templates select="node()" mode="id4483421"/></div><h2>append</h2></axsl:element><h1>after list</h1></div></axsl:template><axsl:template match="node()" mode="id4483421"><axsl:apply-templates select="."/></axsl:template><axsl:template match="li" priority="1" mode="id4483421"><axsl:element name="{name()}"><axsl:apply-templates select="@*"/><axsl:attribute name="title">ding</axsl:attribute><axsl:variable name="orig_classes" select="concat(normalize-space(@class), ' ')"/><axsl:variable name="classes"><axsl:value-of select="$orig_classes"/><axsl:if test="not(contains($orig_classes, 'hey '))">hey </axsl:if><axsl:if test="not(contains($orig_classes, 'foo '))">foo </axsl:if><axsl:if test="not(contains($orig_classes, 'hello '))">hello </axsl:if></axsl:variable><axsl:variable name="trimmed_classes" select="normalize-space($classes)"/><axsl:if test="$trimmed_classes"><axsl:attribute name="class"><axsl:value-of select="$trimmed_classes"/></axsl:attribute></axsl:if><h1 style="color:lightblue;"><axsl:apply-templates select="node()"/></h1></axsl:element></axsl:template><axsl:template match="ding:blah" priority="1"><axsl:element name="h1"><axsl:apply-templates select="@*"/><span>(<axsl:apply-templates select="node()"/>xxx)</span></axsl:element></axsl:template><axsl:template match="processing-instruction('xml-stylesheet')"/></axsl:stylesheet>
<axsl:stylesheet xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:axsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:ding="ding" xmlns:s="structure_stylesheet" version="1.0" exclude-result-prefixes="s xhtml"><axsl:output method="html" encoding="ISO-8859-1"/><axsl:template match="@*|node()"><axsl:copy><axsl:apply-templates select="@*|node()"/></axsl:copy></axsl:template><axsl:template match="xhtml:ul[@id = 'ding'][contains(concat(normalize-space(@class), ' '), 'blah ')]" priority="11011"><div class="wrapper"><h1>before list</h1><axsl:element name="ol"><axsl:apply-templates select="@*"/><axsl:attribute name="title">THIS IS A TITLE</axsl:attribute><axsl:variable name="orig_classes" select="concat(normalize-space(@class), ' ')"/><axsl:variable name="classes"><axsl:value-of select="$orig_classes"/><axsl:if test="not(contains($orig_classes, 'blah '))">blah </axsl:if><axsl:if test="not(contains($orig_classes, 'ding '))">ding </axsl:if><axsl:if test="not(contains($orig_classes, 'hey '))">hey </axsl:if><axsl:if test="not(contains($orig_classes, 'what '))">what </axsl:if></axsl:variable><axsl:variable name="trimmed_classes" select="normalize-space($classes)"/><axsl:if test="$trimmed_classes"><axsl:attribute name="class"><axsl:value-of select="$trimmed_classes"/></axsl:attribute></axsl:if><h2>prepend</h2><div class="innerwrap"><axsl:apply-templates select="node()" mode="id4483438"/></div><h2>append</h2></axsl:element><h1>after list</h1></div></axsl:template><axsl:template match="node()" mode="id4483438"><axsl:apply-templates select="."/></axsl:template><axsl:template match="xhtml:li" priority="1" mode="id4483438"><axsl:element name="{name()}"><axsl:apply-templates select="@*"/><axsl:attribute name="title">ding</axsl:attribute><axsl:variable name="orig_classes" select="concat(normalize-space(@class), ' ')"/><axsl:variable name="classes"><axsl:value-of select="$orig_classes"/><axsl:if test="not(contains($orig_classes, 'hey '))">hey </axsl:if><axsl:if test="not(contains($orig_classes, 'foo '))">foo </axsl:if><axsl:if test="not(contains($orig_classes, 'hello '))">hello </axsl:if></axsl:variable><axsl:variable name="trimmed_classes" select="normalize-space($classes)"/><axsl:if test="$trimmed_classes"><axsl:attribute name="class"><axsl:value-of select="$trimmed_classes"/></axsl:attribute></axsl:if><h1 style="color:lightblue;"><axsl:apply-templates select="node()"/></h1></axsl:element></axsl:template><axsl:template match="ding:blah" priority="1"><axsl:element name="h1"><axsl:apply-templates select="@*"/><span>(<axsl:apply-templates select="node()"/>xxx)</span></axsl:element></axsl:template><axsl:template match="processing-instruction('xml-stylesheet')"/></axsl:stylesheet>

0 comments on commit 68dfe2e

Please sign in to comment.