在XSLT中使用处理指令

我想在XSLT中使用处理指令。

逻辑:如果有<?Table Sideturn?>,则应添加<context:sideturn>

输入:

<table-wrap id="tab_A.1" position="anchor">
  <?Table Sideturn?>
  <label>Table A.1</label>
  <caption/>
  <table>
    <tbody/>
  </table>
</table-wrap

输出应为:

<context:sideturn>
  <table/>
</context:sideturn>

尝试的代码:

<xsl:template match="table">
   <xsl:choose>
      <xsl:when test="preceding-sibling::processing-instruction('Table Sideturn')">
         <context:sideturn>
            <table/>
         </context:sideturn>
      </xsl:when>
      <xsl:otherwise>
         <context:not-sideturn>
            <table/>
         </context:not-sideturn>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

以上我的xpath运行不正常。我该如何解决?我正在使用XSLT 2.0。

谢谢。

liulinjian123 回答:在XSLT中使用处理指令

您可以尝试以下操作:

<xsl:when test="preceding-sibling::processing-instruction('Table Sideturn')">

代替

<xsl:when test="preceding-sibling::processing-instruction('Table')">

因为在元素名称中不允许使用空格。

,

处理指令

book.store_ids

具有<?Table Sideturn?> 的名称和值Table。因此,您需要根据其名称和值进行检查:

Sideturn

如评论中所述,我在这里使用<xsl:when test="preceding-sibling::processing-instruction('Table')[normalize-space() = 'Sideturn']"> ,因为某些处理器可能会将值视为开头有空格。

本文链接:https://www.f2er.com/3168996.html

大家都在问