Convert all element names to lower case with XSL?

前端 未结 2 590
谎友^
谎友^ 2021-01-13 13:51

In XSL, how does one convert all element names in a document to lower case before processing it? We\'re using XSLT 2.0, and we\'ve tried the following but it does not work..

相关标签:
2条回答
  • 2021-01-13 14:04

    It works under Altova XMLSpy:

    XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
    <xsl:output exclude-result-prefixes="xsl xs" indent="yes"/>
    
      <xsl:template match="*">      
        <xsl:element name="{lower-case(local-name())}">
            <xsl:apply-templates/>
        </xsl:element>
      </xsl:template>    
    
    </xsl:stylesheet>
    

    XML Input:

    <?xml version="1.0" encoding="UTF-8"?>
    <A>
      <ITEMS>
        <ITEM/>
        <ITEM/>
      </ITEMS>
    </A>
    

    XML output:

    <?xml version="1.0" encoding="UTF-8"?>
    <a>
        <items>
            <item/>
            <item/>
        </items>
    </a>
    
    0 讨论(0)
  • 2021-01-13 14:21
    translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ", 'abcdefghijklmnopqrstuvwxyz')
    
    0 讨论(0)
提交回复
热议问题