From: Jan Pokorný <jpokorny@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 1/6] rgmanager: ra2rng.xsl: extend infrastructure for XML
Date: Tue, 3 Dec 2013 19:26:12 +0100 [thread overview]
Message-ID: <1386095178-23404-2-git-send-email-jpokorny@redhat.com> (raw)
In-Reply-To: <1386095178-23404-1-git-send-email-jpokorny@redhat.com>
+ tag-self named template (originally for "self-closed") renamed just
to tag as now it's able to recursively dump also the nested >forrest<
as passed with fill-with parameter, i.e., the resulting output tag
is not necessarily self-closed
+ tag-end named template doesn't take attrs parameter (apparently
no used for that, was just copy-paste of tag-start)
+ normalize-space at certain places so as to canonicalize the output
The infrastructure itself was started with commit 008c3f6:
rgmanager: ra2rng.xsl: parametrize and make more flexible
Signed-off-by: Jan Pokorn? <jpokorny@redhat.com>
---
rgmanager/src/resources/ra2rng.xsl | 267 ++++++++++++++++++++++++++++---------
1 file changed, 201 insertions(+), 66 deletions(-)
diff --git a/rgmanager/src/resources/ra2rng.xsl b/rgmanager/src/resources/ra2rng.xsl
index e53595e..046371e 100644
--- a/rgmanager/src/resources/ra2rng.xsl
+++ b/rgmanager/src/resources/ra2rng.xsl
@@ -4,12 +4,12 @@
exclude-result-prefixes="int">
<xsl:output method="text" indent="no"/>
-<xsl:param name="init-indent" select="' '"/>
-<xsl:param name="indent" select="' '"/>
+<xsl:param name="global-init-indent" select="' '"/>
+<xsl:param name="global-indent" select="' '"/>
<!--
- helpers
+ helper definitions
-->
<int:common-optional-parameters>
@@ -59,53 +59,144 @@
<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:param name="indent" select="$global-indent"/>
+ <xsl:param name="indented" select="''"/>
+ <xsl:if test="$indent != 'NONE'">
+ <xsl:value-of select="concat($indented, $indent)"/>
</xsl:if>
- <xsl:value-of select="concat($TS, '!-- ', $text, ' --',$TE)"/>
+ <xsl:value-of select="concat($TS, '!-- ', normalize-space($text), ' --',$TE)"/>
+</xsl:template>
+
+<xsl:template name="text">
+ <xsl:param name="text" select="''"/>
+ <xsl:param name="indent" select="$global-indent"/>
+ <xsl:param name="indented" select="''"/>
+ <xsl:if test="$indent != 'NONE'">
+ <xsl:value-of select="concat($indented, $indent)"/>
+ </xsl:if>
+ <xsl:value-of select="normalize-space($text)"/>
</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:param name="indent" select="$global-indent"/>
+ <xsl:param name="indented" select="''"/>
+ <xsl:if test="$indent != 'NONE'">
+ <xsl:value-of select="concat($indented, $indent)"/>
</xsl:if>
<xsl:value-of select="concat($TS, $name)"/>
<xsl:if test="$attrs != ''">
- <xsl:value-of select="concat($SP, $attrs)"/>
+ <xsl:value-of select="concat($SP, normalize-space($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:param name="indent" select="$global-indent"/>
+ <xsl:param name="indented" select="''"/>
+ <xsl:if test="$indent != 'NONE'">
+ <xsl:value-of select="concat($indented, $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:template name="pretty-print">
+ <xsl:param name="indent" select="$global-indent"/>
+ <xsl:param name="indented" select="''"/>
+ <xsl:param name="fill-with"/>
+ <!--xsl:value-of select="$NL"/-->
+ <xsl:for-each select="$fill-with">
+ <xsl:choose>
+ <xsl:when test="self::comment()">
+ <xsl:value-of select="$NL"/>
+ <xsl:call-template name="comment">
+ <xsl:with-param name="text" select="."/>
+ <xsl:with-param name="indent" select="$indent"/>
+ <xsl:with-param name="indented" select="concat($indented, $indent)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::*">
+ <xsl:if test="count($fill-with/*) < 2
+ or count(preceding-sibling::*) = 0">
+ <xsl:value-of select="$NL"/>
+ </xsl:if>
+ <xsl:call-template name="tag">
+ <xsl:with-param name="name" select="name()"/>
+ <xsl:with-param name="attrs">
+ <xsl:for-each select="@*">
+ <xsl:value-of select="concat(name(), '=', $Q, ., $Q, $SP)"/>
+ </xsl:for-each>
+ </xsl:with-param>
+ <xsl:with-param name="indent" select="$indent"/>
+ <xsl:with-param name="indented" select="concat($indented, $indent)"/>
+ <xsl:with-param name="fill-with"
+ select="node()"/>
+ </xsl:call-template>
+ <xsl:value-of select="$NL"/>
+ </xsl:when>
+ <xsl:when test="self::text()">
+ <xsl:call-template name="text">
+ <xsl:with-param name="text" select="."/>
+ <xsl:with-param name="indent" select="'NONE'"/>
+ <xsl:with-param name="indented" select="$indented"/>
+ </xsl:call-template>
+ <!-- xsl:value-of select="$NL"/ -->
+ </xsl:when>
+ <xsl:value-of select="name()"/>
+ </xsl:choose>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template name="tag">
<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:param name="indent" select="$global-indent"/>
+ <xsl:param name="indented" select="''"/>
+ <xsl:param name="fill-with" select="false()"/>
+ <xsl:choose>
+ <!-- XXX: better test for "empty" fill-with -->
+ <xsl:when test="$fill-with != false()">
+ <xsl:call-template name="tag-start">
+ <xsl:with-param name="name" select="$name"/>
+ <xsl:with-param name="attrs" select="$attrs"/>
+ <xsl:with-param name="indent" select="$indent"/>
+ <xsl:with-param name="indented" select="$indented"/>
+ </xsl:call-template>
+ <xsl:call-template name="pretty-print">
+ <xsl:with-param name="indent" select="$indent"/>
+ <xsl:with-param name="indented" select="$indented"/>
+ <xsl:with-param name="fill-with" select="$fill-with"/>
+ </xsl:call-template>
+ <xsl:call-template name="tag-end">
+ <xsl:with-param name="name" select="$name"/>
+ <xsl:with-param name="indent">
+ <xsl:choose>
+ <xsl:when test="count($fill-with) = 1
+ and $fill-with[1][self::text()]">
+ <xsl:value-of select="'NONE'"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$indent"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ <xsl:with-param name="indented" select="$indented"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="$indent != 'NONE'">
+ <xsl:value-of select="concat($indented, $indent)"/>
+ </xsl:if>
+ <xsl:value-of select="concat($TS, $name)"/>
+ <xsl:if test="$attrs != ''">
+ <xsl:value-of select="concat($SP, normalize-space($attrs))"/>
+ </xsl:if>
+ <xsl:value-of select="$TEc"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<xsl:template name="capitalize">
@@ -142,22 +233,27 @@
<xsl:with-param name="attrs" select="concat(
'name=', $Q, @name, $Q, $SP,
'rha:description=', $Q, normalize-space(shortdesc), $Q)"/>
- <xsl:with-param name="indent" select="$indent"/>
+ <xsl:with-param name="indented"
+ select="$global-init-indent"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- choice (start) -->
<xsl:call-template name="tag-start">
<xsl:with-param name="name" select="'choice'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- group (start) -->
<xsl:call-template name="tag-start">
<xsl:with-param name="name" select="'group'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
@@ -166,37 +262,47 @@
<xsl:with-param name="text">
<xsl:text>rgmanager specific stuff</xsl:text>
</xsl:with-param>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- attribute name="ref" -->
- <xsl:call-template name="tag-self">
+ <xsl:call-template name="tag">
<xsl:with-param name="name" select="'attribute'"/>
<xsl:with-param name="attrs" select="concat(
'name=', $Q, 'ref', $Q, $SP,
'rha:description=', $Q, 'Reference to existing ',
@name, ' resource in ',
'the resources section.', $Q)"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- group (end) -->
<xsl:call-template name="tag-end">
<xsl:with-param name="name" select="'group'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- group (start) -->
<xsl:call-template name="tag-start">
<xsl:with-param name="name" select="'group'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
@@ -204,13 +310,16 @@
<xsl:choose>
<xsl:when test="@required = '1' or @primary = '1'">
<!-- attribute name=... rha:description=... -->
- <xsl:call-template name="tag-self">
+ <xsl:call-template name="tag">
<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)"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
</xsl:when>
@@ -218,28 +327,37 @@
<!-- optional (start) -->
<xsl:call-template name="tag-start">
<xsl:with-param name="name" select="'optional'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- attribute name=... rha:description=... -->
- <xsl:call-template name="tag-self">
+ <xsl:call-template name="tag">
<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)"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent, $indent,
- $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent,
+ $global-indent,
+ $global-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="concat($indent, $indent,
- $indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
</xsl:otherwise>
@@ -249,15 +367,19 @@
<!-- group (end) -->
<xsl:call-template name="tag-end">
<xsl:with-param name="name" select="'group'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- choice (end) -->
<xsl:call-template name="tag-end">
<xsl:with-param name="name" select="'choice'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
@@ -265,25 +387,31 @@
<!-- optional (start) -->
<xsl:call-template name="tag-start">
<xsl:with-param name="name" select="'optional'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- attribute name=... rha:description=... -->
- <xsl:call-template name="tag-self">
+ <xsl:call-template name="tag">
<xsl:with-param name="name" select="'attribute'"/>
<xsl:with-param name="attrs" select="concat(
'name=', $Q, @name, $Q, $SP,
'rha:description=', $Q, normalize-space(int:shortdesc), $Q)"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-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="concat($indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
</xsl:for-each>
@@ -291,31 +419,38 @@
<!-- optional (start) -->
<xsl:call-template name="tag-start">
<xsl:with-param name="name" select="'optional'"/>
- <xsl:with-param name="indent" select="concat($indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- ref name="CHILDREN" -->
- <xsl:call-template name="tag-self">
+ <xsl:call-template name="tag">
<xsl:with-param name="name" select="'ref'"/>
<xsl:with-param name="attrs" select="concat(
'name=', $Q, 'CHILDREN', $Q)"/>
- <xsl:with-param name="indent" select="concat($indent, $indent,
- $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent,
+ $global-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="concat($indent, $indent)"/>
+ <xsl:with-param name="indented"
+ select="concat($global-init-indent,
+ $global-indent)"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
<!-- element (end) -->
<xsl:call-template name="tag-end">
<xsl:with-param name="name" select="'element'"/>
- <xsl:with-param name="indent" select="$indent"/>
+ <xsl:with-param name="indented"
+ select="$global-init-indent"/>
</xsl:call-template>
<xsl:value-of select="$NL"/>
--
1.8.1.4
next prev parent reply other threads:[~2013-12-03 18:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-03 18:26 [Cluster-devel] [resource-agents][PATCH 0/6] rgmanager: ra2rng.xsl: build up param datatyping infra Jan Pokorný
2013-12-03 18:26 ` Jan Pokorný [this message]
2013-12-03 18:26 ` [Cluster-devel] [PATCH 2/6] rgmanager: ra2rng.xsl: make common params reuse XML pretty-print Jan Pokorný
2013-12-03 18:26 ` [Cluster-devel] [PATCH 3/6] rgmanager: ra2rng.xsl: common params: prevent misleading combination Jan Pokorný
2013-12-03 18:26 ` [Cluster-devel] [PATCH 4/6] rgmanager: ra2rng.xsl: control flow branches common business merge Jan Pokorný
2013-12-09 14:14 ` [Cluster-devel] [PATCHv2 " Jan Pokorný
2013-12-03 18:26 ` [Cluster-devel] [PATCH 5/6] rgmanager: ra2rng.xsl: infra for param value datatyping/restriction Jan Pokorný
2013-12-09 14:15 ` [Cluster-devel] [PATCHv2 " Jan Pokorný
2013-12-03 18:26 ` [Cluster-devel] [PATCH 6/6] gmanager: ra2rng.xsl: script-file: try to prevent cluster's services Jan Pokorný
2013-12-03 18:31 ` Jan Pokorný
2013-12-03 18:26 ` [Cluster-devel] [PATCH 6/6] rgmanager: " Jan Pokorný
2013-12-04 13:50 ` [Cluster-devel] [PATCHv2 " Jan Pokorný
2013-12-09 14:16 ` [Cluster-devel] [PATCHv3 " Jan Pokorný
2013-12-05 17:13 ` [Cluster-devel] [PATCHv2 3/6] rgmanager: ra2rng.xsl: common params: prevent misleading combination Jan Pokorný
2013-12-09 14:12 ` [Cluster-devel] [PATCHv3 " Jan Pokorný
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386095178-23404-2-git-send-email-jpokorny@redhat.com \
--to=jpokorny@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).