小编Bhu*_*ana的帖子

使用XSLT将变量值作为元素名称

我正在将一种格式的XML转换为另一种格式,我需要插入一个元素并将其命名为变量值.例如,我正在尝试使用XSLT的下面的语句,但我从处理器收到一个错误,说元素名称无效.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">

    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="no" omit-xml-declaration="no"/>

    <xsl:variable name="i" select="i"/>
    <xsl:variable name="b" select="b"/>
    <xsl:variable name="u" select="u"/>
    <xsl:variable name="s" select="s"/>
    <xsl:variable name="r" select="r"/>
    <xsl:variable name="m" select="m"/>
    <xsl:variable name="n" select="n"/>

<xsl:template match="/|comment()|processing-instruction()">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

<xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>

<xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="."/>
    </xsl:attribute>
</xsl:template>

    <xsl:template match="//w:r">
        <xsl:if test="not(./descendant::w:i)">
         <xsl:variable name="i">0</xsl:variable>            
        </xsl:if>
        <xsl:if test="not(./descendant::w:b)">
         <xsl:variable name="b">0</xsl:variable>            
        </xsl:if>
        <xsl:if test="not(./descendant::w:u)">
         <xsl:variable name="u">0</xsl:variable>            
        </xsl:if>
        <xsl:if test="not(./descendant::w:caps)">
         <xsl:variable name="c">0</xsl:variable>            
        </xsl:if>

        <xsl:if test="not(contains($i,'0'))">
            <xsl:variable name="r" …
Run Code Online (Sandbox Code Playgroud)

xslt xslt-2.0 xslt-1.0

20
推荐指数
1
解决办法
4万
查看次数

标签 统计

xslt ×1

xslt-1.0 ×1

xslt-2.0 ×1