+ 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ý <jpoko...@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