xslt - 有没有办法在 xsl :if test? 中使用模式

标签 xslt xslt-2.0 mode

我一直在学习将模式属性与 XSLT 一起使用,并且想知道是否有一种方法可以在模板中(例如在 xsl:if 语句中)测试它?我只看到它在 xsl:template 级别使用,也许这是唯一的方法。假设我想在路径属性 (@href) 前面添加“../”,但前提是 mode="print":

     <xsl:template name="object" mode="#all">
        <img>
         <xsl:attribute name="src">
          <xsl:if test="mode='print'"><xsl:text>../</xsl:text></xsl:if>
          <xsl:value-of select="@href"/>
         </xsl:attribute>
        </img>
     </xsl:template>

我正在调用带有或不带有从各种其他模板设置的 mode="print"的 apply-templates。

当然,我可以使用 mode="print"创建一个新模板,但随后我必须维护两个模板。

或者也许有更好的方法来做到这一点?谢谢您的帮助。 - 斯科特

最佳答案

目前还没有直接的方法可以做到这一点。一种方法可以是-

<xsl:template match="/">

   <xsl:apply-templates select="something" mode="a">
      <xsl:with-param name="mode" select="'a'" tunnel="yes"/>
   </xsl:apply-templates>

   <xsl:apply-templates select="something" mode="b">
      <xsl:with-param name="mode" select="'b'" tunnel="yes"/>
   </xsl:apply-templates>

</xsl:template>

然后在比赛中-

<xsl:template match="blah" mode="a b">
   <xsl:param name="mode" tunnel="yes"/>

   <xsl:if test="$mode='a'">
     <!-- Do Something -->
   </xsl:if>

   <xsl:if test="$mode='b'">
     <!-- Do Something -->
   </xsl:if>

</xsl:template>

关于xslt - 有没有办法在 xsl :if test? 中使用模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26370734/

相关文章:

java - 将 .gpx 文件中的数据解析为 CSV 文件

sql - SELECT 模式/模态值 SQL

java - fo :data-cell overflow

java - XSL 的后处理步骤

xslt - XSLT 转换中的动态文档类型(正确使用结果文档指令)

xslt-2.0 - XSLT 2.0 : Find missing elements in a sequence

emacs - 检查模式是否在emacs上

c++ - 寻找模式 C++

xml - 你如何选择child-or-self(children+self)

Java 在 XSL 转换中将 byte[] 发送到 base64Binary