首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >匹配具有命名空间的节点

匹配具有命名空间的节点
EN

Stack Overflow用户
提问于 2021-06-12 01:27:23
回答 1查看 55关注 0票数 0

我有一个原始的xml:

代码语言:javascript
复制
<Document xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.12.x/InforOAGIS/BODs/SyncCaptureDocument.xsd" releaseID="9.2" versionID="2.12.2">
    <Application>
        <Sender>
            <LogicalID>lid://infor.daf.1</LogicalID>
            <Code>OnError</Code>
        </Sender>
        <CreationDateTime>2021-06-10T23:07:36.193Z</CreationDateTime>
    </Application>
</Document>

到目前为止,我的XSLT:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:ns0="http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.12.x/InforOAGIS/BODs/SyncCaptureDocument.xsd"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:output method="xml" indent="yes" html-version="5"/>

  <xsl:template match="/">
        <Transaction xmlns="http://schema.infor.com/InforOAGIS/2"
                     languageCode="en-US"
                     releaseID="9.2"
                     systemEnvironmentCode="Production"
                     versionID="2.8.0">
            
            <ApplicationArea>
                <Sender>
                    <LogicalID>
                        <xsl:value-of select="ns0:Document/ns0:Application/ns0:Sender/ns0:LogicalID"/>
                    </LogicalID>
                    <Code>Add</Code>
                </Sender>
                <CreationDateTime>2021-06-10T23:07:36.193Z</CreationDateTime>
            </ApplicationArea>
            
        </Transaction>
    
  </xsl:template>
  
</xsl:stylesheet>

我无法将<LogicalID>节点与上面的代码相匹配。我想是因为名字空间。任何帮助都是非常感谢的。链接到xslt:https://xsltfiddle.liberty-development.net/eieFA13/1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-12 04:42:37

XSLT中的命名空间声明是错误的,请参见https://xsltfiddle.liberty-development.net/eieFA13/2中仅绑定名称空间名称(例如xmlns:ns0="http://schema.infor.com/InforOAGIS/2")或使用xpath默认名称空间(例如xpath-default-namespace="http://schema.infor.com/InforOAGIS/2")简化任务的修正。

另一方面,听起来更像是要更改Sender/Code元素:

代码语言:javascript
复制
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xpath-default-namespace="http://schema.infor.com/InforOAGIS/2"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="Sender/Code">
      <xsl:copy>Add</xsl:copy>
  </xsl:template>  
  
</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/eieFA13/4

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

https://stackoverflow.com/questions/67944911

复制
相关文章

相似问题

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