* [Cluster-devel] [PATCH][fence-agents] fence2rng.xsl: parametrize and make more flexible
@ 2013-03-01 10:23 Jan Pokorný
0 siblings, 0 replies; only message in thread
From: Jan Pokorný @ 2013-03-01 10:23 UTC (permalink / raw)
To: cluster-devel.redhat.com
The output is 1:1 to the previous version, but it is now easy to change
base indentation level and internally, we use abstract blocks for tags
instead of </> kludge. Also the unused macro-like template is
removed.
Signed-off-by: Jan Pokorn? <jpokorny@redhat.com>
---
fence/agents/lib/fence2rng.xsl | 171 +++++++++++++++++++++++++++++++++++++----
1 file changed, 156 insertions(+), 15 deletions(-)
diff --git a/fence/agents/lib/fence2rng.xsl b/fence/agents/lib/fence2rng.xsl
index a958de1..432bc89 100644
--- a/fence/agents/lib/fence2rng.xsl
+++ b/fence/agents/lib/fence2rng.xsl
@@ -1,20 +1,161 @@
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-<xsl:output method="text" indent="yes"/>
-<xsl:template name="capitalize">
- <xsl:param name="value"/>
- <xsl:variable name="normalized" select="translate($value, '_abcdefghijklmnopqrstuvwrxyz', '-ABCDEFGHIJKLMNOPQRSTUVWRXYZ')"/>
- <xsl:value-of select="$normalized"/>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method="text" indent="no"/>
+
+<xsl:param name="init-indent" select="' '"/>
+<xsl:param name="indent" select="' '"/>
+
+
+<!--
+ helpers
+ -->
+
+<xsl:variable name="SP" select="' '"/>
+<xsl:variable name="NL" select="'
'"/>
+<xsl:variable name="Q" select="'"'"/>
+<xsl:variable name="TS" select="'<'"/>
+<xsl:variable name="TSc" select="'</'"/>
+<xsl:variable name="TE" select="'>'"/>
+<xsl:variable name="TEc" select="'/>'"/>
+
+<xsl:template name="comment">
+ <xsl:param name="text" select="''"/>
+ <xsl:param name="indent" select="''"/>
+ <xsl:if test="$indent != 'none'">
+ <xsl:value-of select="concat($init-indent, $indent)"/>
+ </xsl:if>
+ <xsl:value-of select="concat($TS, '!-- ', $text, ' --',$TE)"/>
+</xsl:template>
+
+<xsl:template name="tag-start">
+ <xsl:param name="name"/>
+ <xsl:param name="attrs" select="''"/>
+ <xsl:param name="indent" select="''"/>
+ <xsl:if test="$indent != 'none'">
+ <xsl:value-of select="concat($init-indent, $indent)"/>
+ </xsl:if>
+ <xsl:value-of select="concat($TS, $name)"/>
+ <xsl:if test="$attrs != ''">
+ <xsl:value-of select="concat($SP, $attrs)"/>
+ </xsl:if>
+ <xsl:value-of select="$TE"/>
+</xsl:template>
+
+<xsl:template name="tag-end">
+ <xsl:param name="name"/>
+ <xsl:param name="attrs" select="''"/>
+ <xsl:param name="indent" select="''"/>
+ <xsl:if test="$indent != 'none'">
+ <xsl:value-of select="concat($init-indent, $indent)"/>
+ </xsl:if>
+ <xsl:value-of select="concat($TSc, $name)"/>
+ <xsl:if test="$attrs != ''">
+ <xsl:value-of select="concat($SP, $attrs)"/>
+ </xsl:if>
+ <xsl:value-of select="$TE"/>
</xsl:template>
+
+<xsl:template name="tag-self">
+ <xsl:param name="name"/>
+ <xsl:param name="attrs" select="''"/>
+ <xsl:param name="indent" select="''"/>
+ <xsl:if test="$indent != 'none'">
+ <xsl:value-of select="concat($init-indent, $indent)"/>
+ </xsl:if>
+ <xsl:value-of select="concat($TS, $name)"/>
+ <xsl:if test="$attrs != ''">
+ <xsl:value-of select="concat($SP, $attrs)"/>
+ </xsl:if>
+ <xsl:value-of select="$TEc"/>
+</xsl:template>
+
+
+<!--
+ proceed
+ -->
+
<xsl:template match="/resource-agent">
- <!-- <xsl:value-of select="@name"/> -->
- <group rha:name="<xsl:value-of select="@name"/>" rha:description="<xsl:value-of select="@shortdesc"/>">
- <optional>
- <attribute name="option"/> <!-- deprecated; for compatibility. use "action" -->
- </optional><xsl:for-each select="parameters/parameter">
- <optional>
- <attribute name="<xsl:value-of select="@name"/>" rha:description="<xsl:value-of select="normalize-space(shortdesc)"/>" />
- </optional></xsl:for-each>
- </group>
+ <xsl:value-of select="$NL"/>
+
+ <!-- (comment denoting the fence agent name) -->
+ <xsl:call-template name="comment">
+ <xsl:with-param name="text" select="@name"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+
+ <!-- group rha:name=... rha:description=... (start) -->
+ <xsl:call-template name="tag-start">
+ <xsl:with-param name="name" select="'group'"/>
+ <xsl:with-param name="attrs" select="concat(
+ 'rha:name=', $Q, @name, $Q, $SP,
+ 'rha:description=', $Q, @shortdesc, $Q)"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+
+ <!-- optional (start) -->
+ <xsl:call-template name="tag-start">
+ <xsl:with-param name="name" select="'optional'"/>
+ <xsl:with-param name="indent" select="$indent"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+
+ <!-- attribute name="option" -->
+ <xsl:call-template name="tag-self">
+ <xsl:with-param name="name" select="'attribute'"/>
+ <xsl:with-param name="attrs" select="concat(
+ 'name=', $Q, 'option', $Q)"/>
+ <xsl:with-param name="indent" select="concat($indent, $indent)"/>
+ </xsl:call-template>
+ <xsl:value-of select="$SP"/>
+ <!-- (comment mentioning that "option" is deprecated) -->
+ <xsl:call-template name="comment">
+ <xsl:with-param name="text">
+ <xsl:text>deprecated; for compatibility. use "action"</xsl:text>
+ </xsl:with-param>
+ <xsl:with-param name="indent" select="'none'"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+ <!-- optional (end) -->
+ <xsl:call-template name="tag-end">
+ <xsl:with-param name="name" select="'optional'"/>
+ <xsl:with-param name="indent" select="$indent"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+
+ <xsl:for-each select="parameters/parameter">
+ <!-- optional (start) -->
+ <xsl:call-template name="tag-start">
+ <xsl:with-param name="name" select="'optional'"/>
+ <xsl:with-param name="indent" select="$indent"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+
+ <!-- attribute name=... rha:description=... -->
+ <xsl:call-template name="tag-self">
+ <xsl:with-param name="name" select="'attribute'"/>
+ <xsl:with-param name="attrs" select="concat(
+ 'name=', $Q, @name, $Q, $SP,
+ 'rha:description=', $Q, normalize-space(shortdesc), $Q, $SP)"/>
+ <xsl:with-param name="indent" select="concat($indent, $indent)"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+
+ <!-- optional (end) -->
+ <xsl:call-template name="tag-end">
+ <xsl:with-param name="name" select="'optional'"/>
+ <xsl:with-param name="indent" select="$indent"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+ </xsl:for-each>
+
+ <!-- group rha:name=... rha:description=... (end) -->
+ <xsl:call-template name="tag-end">
+ <xsl:with-param name="name" select="'group'"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+
+ <xsl:value-of select="$NL"/>
</xsl:template>
+
</xsl:stylesheet>
--
1.7.11.7
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-03-01 10:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-01 10:23 [Cluster-devel] [PATCH][fence-agents] fence2rng.xsl: parametrize and make more flexible Jan Pokorný
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).