【问题标题】:How to add attributes to a tag on the basis of child element tag's attribute in xslt如何根据xslt中子元素标签的属性为标签添加属性
【发布时间】:2019-01-29 08:54:47
【问题描述】:

我需要将具有以下属性的所有标签转换为代码块标签

    <span style="font-family:courier new,courier,monospace;">
    <span class="mt-font-courier-new">

【问题讨论】:

    标签: html xml attributes xslt-1.0


    【解决方案1】:

    您需要定义一个特定的模板来处理这种情况:

    <xsl:apply templates="*" />
    
    <xsl:template match="span[contains(@style, 'courier')]|span[contains(@style, 'courier')]|span[contains(@class, 'courier')]">
        <codeblock>
            <xsl:apply-templates />
        </codeblock>
    </xsl:template>
    

    您当然可以使用精确值定义选择器,或者通过包含使用模糊匹配来获取这些标签。

    【讨论】:

      【解决方案2】:

      现在它工作正常..感谢您的回复:)

      通过使用此代码:

      <xsl:template match="span[contains(@style, 'font-family:courier new,courier,monospace;')]|span[contains(@class, 'mt-font-courier-new')]">
          <codeblock>
              <xsl:apply-templates />
          </codeblock>
      </xsl:template>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-04
        • 1970-01-01
        • 2020-10-24
        • 1970-01-01
        • 2022-09-24
        • 1970-01-01
        • 1970-01-01
        • 2014-01-08
        相关资源
        最近更新 更多