c1map: Add lvm:when

This allows for conditional nodes where lvm:if is not appropriate or cannot be
used.
master v2.14.0
Mike Gerwitz 2018-04-06 14:56:47 -04:00 committed by Shelly Shaver
parent 6d0f4fd458
commit 8a17d0c6c5
2 changed files with 65 additions and 2 deletions

View File

@ -338,8 +338,27 @@
mode="lvmp:c1-node-result" priority="5">
<lvmp:for-each name="{@lvm:for-each}">
<!-- proceed with processing as normal -->
<xsl:apply-templates select="@*|*" />
<xsl:choose>
<xsl:when test="lvm:when">
<lvmp:condition when="true">
<lvmp:when>
<xsl:call-template name="lvmp:gen-val">
<xsl:with-param name="name" select="lvm:when/@name" />
</xsl:call-template>
</lvmp:when>
<lvmp:cmp>
<xsl:apply-templates mode="lvm:valparse"
select="lvm:when/@eq" />
</lvmp:cmp>
<xsl:apply-templates select="@*|*" />
</lvmp:condition>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@*|*" />
</xsl:otherwise>
</xsl:choose>
</lvmp:for-each>
</xsl:template>
@ -366,6 +385,11 @@
</xsl:template>
<xsl:template match="lvm:when" priority="4">
<!-- handled as part of @lvm:for-each -->
</xsl:template>
<!--
Unhandled node character data

View File

@ -291,6 +291,25 @@
</xsl:template>
<xsl:template match="lvmp:for-each[ lvmp:condition[ @when ] ]" mode="lvmp:render" priority="8">
<xsl:variable name="from">
<xsl:call-template name="lvmp:var-from">
<xsl:with-param name="name" select="@name" />
</xsl:call-template>
</xsl:variable>
<xsl:text>$contract->iterateValues( '</xsl:text>
<xsl:value-of select="$from" />
<xsl:text>', </xsl:text>
<xsl:text>function( $contract ) {</xsl:text>
<xsl:text> return </xsl:text>
<xsl:apply-templates mode="lvmp:render" select="lvmp:condition" />
<xsl:text>;</xsl:text>
<xsl:text>}</xsl:text>
<xsl:text>)</xsl:text>
</xsl:template>
<!--
The C1 import system recognizes the following formats:
@ -353,6 +372,26 @@
</xsl:template>
<xsl:template mode="lvmp:render" priority="8" match="lvmp:condition[ @when ]">
<xsl:variable name="cond" select="." />
<xsl:text>( ( </xsl:text>
<xsl:text>$contract->isTruthy( </xsl:text>
<xsl:apply-templates select="$cond/lvmp:when/lvmp:*" mode="lvmp:render" />
<xsl:if test="$cond/lvmp:cmp/*">
<xsl:text>,</xsl:text>
<xsl:apply-templates select="$cond/lvmp:cmp/lvmp:*" mode="lvmp:render" />
</xsl:if>
<xsl:text>)</xsl:text>
<xsl:text> ) ? array(</xsl:text>
<xsl:apply-templates mode="lvmp:render">
<xsl:with-param name="no-trailing-sep" select="true()" />
</xsl:apply-templates>
<xsl:text>) : null )</xsl:text>
</xsl:template>
<xsl:template match="*" mode="lvmp:render" priority="1">
<xsl:message terminate="yes">
<xsl:text>[c1map] fatal: unexpected node during render: </xsl:text>