XSLT避免xmlns="&引用;在XML元素中
我正在努力转换所附的文件。我尝试过各种场景,但我认为问题在于我对XSLT和名称空间的知识泄漏。我必须在输出中获得结果,避免xmlns=”“。 谢谢XSLT避免xmlns="&引用;在XML元素中,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,我正在努力转换所附的文件。我尝试过各种场景,但我认为问题在于我对XSLT和名称空间的知识泄漏。我必须在输出中获得结果,避免xmlns=”“。 谢谢 http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.10.x/InforOAGIS/BODs/SyncItemMaster.xsd 2.10.x 企业资源计划 您好,这里是我要转换的输入。SyncMatserItem有自己正确的名称空间,但我必须从所有降序元素中去掉xmln
http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.10.x/InforOAGIS/BODs/SyncItemMaster.xsd
2.10.x
企业资源计划
您好,这里是我要转换的输入。SyncMatserItem有自己正确的名称空间,但我必须从所有降序元素中去掉xmlns=“”,例如
<SyncItemMaster releaseID="9.2">
<ApplicationArea>
<Sender>
<LogicalID>infor.databaseion_app_6916_Advoco_LN_To_EAM_SyncItemMaster</LogicalID>
<ComponentID>External</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-11-20T16:14:38.747Z</CreationDateTime>
<BODID>infor.databaseion_app_6916_Advoco_LN_To_EAM_SyncItemMaster:1574266478747:12561:0</BODID>
</ApplicationArea>
<DataArea>
<Sync>
<TenantID>infor</TenantID>
<AccountingEntityID>515</AccountingEntityID>
<LocationID/>
<ActionCriteria>
<ActionExpression actionCode="Add"/>
</ActionCriteria>
</Sync>
<ItemMaster>
<ItemMasterHeader>
<ItemID>
<ID accountingEntity="515" lid="lid://infor.ln.ln_brubln03_comp-515" variationID="41759">G33167</ID>
</ItemID>
</ItemMasterHeader>
</ItemMaster>
</DataArea></SyncItemMaster>
信息数据库\u应用程序\u 6916\u Advoco\u LN\u至\u EAM\u SyncItemMaster
外部的
一个错误
2019-11-20T16:14:38.747Z
信息数据库\u应用程序\u Advoco\u LN\u至\u EAM\u SyncItemMaster:1574266478747:12561:0
信息
515
G33167
此处,实际输出:
<?xml version="1.0" encoding="utf-8"?>
<SyncItemMaster xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.10.x/InforOAGIS/BODs/SyncItemMaster.xsd" versionID="2.10.x" releaseID="9.2">
<ApplicationArea xmlns="">
<Sender>
<LogicalID>lid://infor.ln.ln_brubln03_comp-515</LogicalID>
<ComponentID>erp</ComponentID>
<ConfirmationCode>OnError</ConfirmationCode>
</Sender>
<CreationDateTime>2019-11-20T16:14:38.747Z</CreationDateTime>
<BODID>infor-nid:infor:515::G33167:?ItemMaster&verb=Sync</BODID>
</ApplicationArea>
<DataArea xmlns="">
...
lid://infor.ln.ln_brubln03_comp-515
企业资源计划
一个错误
2019-11-20T16:14:38.747Z
infornid:infor:515::G33167:?ItemMaster&;动词=同步
...
样式表中有一条说明:
<xsl:template match="/*">
<xsl:element name="SyncItemMaster" xmlns="http://schema.infor.com/InforOAGIS/2" >
<xsl:attribute name="xsi:schemaLocation" namespace="http://www.w3.org/2001/XMLSchema-instance">http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.10.x/InforOAGIS/BODs/SyncItemMaster.xsd</xsl:attribute>
<xsl:namespace name="xsd" select = "'http://www.w3.org/2001/XMLSchema'" />
然后,您可以使用其他模板创建将成为根元素的子元素或子元素的其他元素,例如:
<xsl:template match="SyncItemMaster/ApplicationArea/Sender/LogicalID">
<xsl:element name="LogicalID"><xsl:value-of select="$lid"/></xsl:element>
</xsl:template>
注意
xsl:stylesheet
start标记中的默认名称空间声明 请给出输入和预期输出的示例,以便我们重现您的问题-请参阅:。——还要用您正在使用的XSLT版本进行澄清:您的问题被标记为XSLT-1.0
,但您的样式表上显示的是version=“2.0”
。关键是要考虑您希望元素的名称是什么(其中名称是[namespace,local name]对)。如果在正确的名称空间中创建元素,序列化输出中的名称空间声明将自行处理。xmlns=“”
取消声明是在命名空间中创建父元素,而在没有命名空间的情况下创建子元素时出现的。很抱歉,我想我现在知道了如何发布代码:-)。您没有发布预期的输出。而且您没有说明您使用的是哪个版本的XSLT。为什么有必要问两次?Michael,版本是上面XSLT的第一行,我想:so 2.0?再次说明:预期输出位于注释的正上方。。。避免在应用程序区域和数据区域使用xmlns=“”。感谢Michael,理论现在已经很清楚了,您可以发布示例代码来实现这一点吗?我用输入和输出代码.Tkx进行了编辑。Marco.Michael,这在XSLT2.0中也适用于我,很好,谢谢。如果您的问题得到了回答,请通过接受答案来结束它。
<SyncItemMaster xmlns:xsd="http://www.w3.org/2001/XMLSchema"
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.10.x/InforOAGIS/BODs/SyncItemMaster.xsd"
versionID="2.10.x"/>
<xsl:template match="SyncItemMaster/ApplicationArea/Sender/LogicalID">
<xsl:element name="LogicalID"><xsl:value-of select="$lid"/></xsl:element>
</xsl:template>
<xsl:stylesheet version=".0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://schema.infor.com/InforOAGIS/2">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- MOVE ALL ELEMENTS TO THE DEFAULT NAMESPACE -->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="/SyncItemMaster">
<SyncItemMaster xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.infor.com/InforOAGIS/2 http://schema.infor.com/2.10.x/InforOAGIS/BODs/SyncItemMaster.xsd">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</SyncItemMaster>
</xsl:template>
<xsl:template match="LogicalID">
<LogicalID>
<xsl:value-of select="/SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/ItemID/ID/@lid"/>
</LogicalID>
</xsl:template>
<xsl:template match="ComponentID">
<ComponentID>erp</ComponentID>
</xsl:template>
<xsl:template match="BODID">
<BODID>
<xsl:text>infor-nid:infor:515::</xsl:text>
<xsl:value-of select="/SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/ItemID/ID" />
<xsl:text>:?ItemMaster&verb=Sync</xsl:text>
</BODID>
</xsl:template>
</xsl:stylesheet>