首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSL转换失败:预期的QName

XSL转换失败:预期的QName
EN

Stack Overflow用户
提问于 2015-05-14 10:43:06
回答 1查看 916关注 0票数 1

当我试图使用下面的样式表转换一个XMl时,由于Expected QName错误,转换失败了。下面粘贴的样式表到底缺少什么?

代码语言:javascript
复制
 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp">
        <xsl:output method="xml" indent="yes" version="1.0"/>
        <xsl:variable name="origo-svc-augmented" select="'Y'"/>
        <xsl:variable name="origo-svc-ns" select="'http://www.origoservices.com'"/>
        <xsl:template match="node()">
                    <xsl:variable name="namespace" select="namespace-uri(.)"/>
                    <xsl:choose>
                                <!--xsl:when test="$namespace = ''
                  or ($origo-svc-augmented='Y' and $namespace=$origo-svc-ns)"-->
                                <xsl:when test="$origo-svc-augmented = 'N'">
                                            <xsl:element name="{local-name()}">
                                                        <xsl:copy-of select="namespace::*[not(namespace-uri()=$origo-svc-ns)]"/>
                                                        <xsl:apply-templates select="@*|node()|comment()|processing-instruction()|text()"/>
                                            </xsl:element>
                                </xsl:when>
                                <xsl:otherwise>
                                            <xsl:element name="{local-name()}" namespace="{$namespace}">
                                                        <xsl:copy-of select="namespace::*"/>
                                                        <xsl:apply-templates select="@*|node()|comment()|processing-instruction()|text()"/>
                                            </xsl:element>
                                </xsl:otherwise>
                    </xsl:choose>
        </xsl:template>

</xsl:stylesheet>

更新:在应用了来自所提供的答案的建议之后,样式表运行良好,更新的样式表如下所示

代码语言:javascript
复制
 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp">
        <xsl:output method="xml" indent="yes" version="1.0"/>
        <xsl:variable name="origo-svc-augmented" select="'Y'"/>
        <xsl:variable name="origo-svc-ns" select="'http://www.origoservices.com'"/>
        <xsl:template match="*">
                    <xsl:variable name="namespace" select="namespace-uri(.)"/>
                    <xsl:choose>
                                <!--xsl:when test="$namespace = ''
                  or ($origo-svc-augmented='Y' and $namespace=$origo-svc-ns)"-->
                                <xsl:when test="$origo-svc-augmented = 'Y'">
                                            <xsl:element name="{local-name()}">
                                                        <xsl:copy-of select="namespace::*[not(namespace-uri()=$origo-svc-ns)]"/>
                                                        <xsl:apply-templates select="@*|node()|comment()|processing-instruction()|text()"/>
                                            </xsl:element>
                                </xsl:when>
                                <xsl:otherwise>
                                            <xsl:element name="{local-name()}" namespace="{$namespace}">
                                                        <xsl:copy-of select="namespace::*"/>
                                                        <xsl:apply-templates select="@*|node()|comment()|processing-instruction()|text()"/>
                                            </xsl:element>
                                </xsl:otherwise>
                    </xsl:choose>
        </xsl:template>
        <xsl:template match="@*|comment()|processing-instruction()|text()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()|comment()|processing-instruction()|text()"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-14 10:59:43

我还没有试过,但我认为这可能是因为您正在node()上匹配(即元素、文本节点、处理指令注释),然后尝试创建一个元素,该元素的名称可能是非元素节点。QName指的是一个有效的XML名称,例如,我假设一个文本节点不会有一个(当您调用local-name()时)。您可以将模板匹配更改为*,并为其他类型添加另一个模板。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30235298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档