xslt - 将节点与命名空间匹配
问题描述
我有这个原始的xml:
<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:
<?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
解决方案
XSLT 中的命名空间声明错误,请参阅 https://xsltfiddle.liberty-development.net/eieFA13/2中的修复以仅绑定命名空间名称(例如xmlns:ns0="http://schema.infor.com/InforOAGIS/2"
)或https://xsltfiddle.liberty-development.net/ eieFA13/3 通过使用 xpath-default-namespace(例如xpath-default-namespace="http://schema.infor.com/InforOAGIS/2"
)来简化任务。
另一方面,这听起来更像是您想更改Sender/Code
元素:
<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>
推荐阅读
- aws-lambda - API Gateway 和 AWS Lambda 函数的问题:格式错误的 Lambda 代理响应
- html - 在wordpress中找不到html文件
- c# - 调用sql查询时如何调用lambda表达式?
- css - css 选择不被同一个类跟随的元素
- google-apps-script - 将最后一个表单响应复制到新的最后一行其他工作表
- c - 按值传递和按引用传递有什么区别?
- openstreetmap - GraphHopper:禁用 OSM 方式崩溃
- html - 如何使用 html 和 css 在按钮上正确定位文本和图标
- mongodb - 如何使用 mongodb 聚合按属性创建地图
- javascript - 如何正确指定Route by:两个条件下的id