Need to include the working code with multiple cyclic mode is not working

喜你入骨 提交于 2020-08-10 20:13:51

问题


I need to run all templates on the mode based, So I'm having firstmode which is needs to run the corresponding template based mode

Input I'm having:

<section>
<p class="p heading">Heading</p>
<p class="normal">Text</p>
</section>

Working XSL:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">
    
    <xsl:template match="*">
        
        <xsl:variable name="firstmode">
            <xsl:element name="{name()}">
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates mode="firstmode"/>
            </xsl:element>
        </xsl:variable>
    
        <xsl:sequence select="$firstmode"/>
        
    </xsl:template>
    
    <xsl:template match="*" mode="firstmode">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="firstmode"/>
        </xsl:copy>
    </xsl:template>
    
    
  <xsl:param name="class-map">
   <name>
      <old>heading</old>
      <new>Headings</new>
   </name>
   <name>
      <old>normal</old>
      <new>Actual</new>
   </name>
  </xsl:param>
  
  <xsl:key name="class-map" match="name/new" use="../old"/>
  
  <xsl:template match="p/@class[key('class-map', tokenize(.), $class-map)]" mode="firstmode">
      <xsl:attribute name="style">
      <xsl:attribute name="{name()}" select="key('class-map', tokenize(.) , $class-map)"/>
      </xsl:attribute>
  </xsl:template>
  
  <xsl:template match="p" mode="firstmode">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <normal>
      <xsl:apply-templates/>
    </normal>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Expected Output:

<p style="Headings"><normal>Heading</normal></p>
<p style="Actual"><normal>Text</normal></p>

Once included the mode="firstmode" in the templates, the expected outputs are not getting. Please provide me the suggestion for how to handling this.

来源:https://stackoverflow.com/questions/63302183/need-to-include-the-working-code-with-multiple-cyclic-mode-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!