gpt4 book ai didi

xslt - 我们如何将 XML 元素转换为 xslt 中的不同 namespace

转载 作者:行者123 更新时间:2023-12-01 04:30:53 24 4
gpt4 key购买 nike

我有一个输入 xml

<Request xmlns="http://hgkg.ghg.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<AppointmentInfo xmlns="">

<AppointmentId/>

<CountryCode>US</CountryCode>

<Division>A</Division>
</AppointmentInfo>
<AppointDate xmlns="">
<Day>Monday</Day>
<Date>April 2</Date>
<AppointDate>

</Request>

我需要这样的输出

<Request xmlns="http://hgkg.ghg.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<AppointmentInfo>

<AppointmentId/>

<CountryCode>US</CountryCode>

<Division>A</Division>
</AppointmentInfo>
<AppointDate>
<Day>Monday</Day>
<Date>April 2</Date>
<AppointDate>
</Request>

我只想删除其中的 xmlns=""并假设响应 AppointmentInfo 和 AppointDate 在 hgkg 命名空间中。我想转换成它..请帮助我

最佳答案

基于 JLRishe's earlier answer ,你可以试试这个:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

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

这意味着,不是最外层元素 (match="*/*") 的每个元素都被复制到具有相同名称但具有最外层元素命名空间的输出元素(命名空间-uri(/*))。

看看是否可行...

关于xslt - 我们如何将 XML 元素转换为 xslt 中的不同 namespace ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15979732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com