xml - Azure 集成帐户 (Maps - XSLT) - 使用逻辑应用将 2 个不同的 XML 合并为单个 xml
问题描述
在 Azure 逻辑应用中,我有 2 个不同的 JSON 格式的 xml 文件 Parent.xml 和 Children.xml。
要求 - 我需要使用存储在集成帐户中的 XSLT 创建将这 2 个文件合并到单个 Family.xml 文件中。
**使用内置 C# 代码为自定义代码逻辑创建 XSLT 时需要帮助。此 XSLT 需要放置在 Azure 集成帐户的映射中。**
以下是样本:-
父.xml
<ParentRoot>
<ParentName>
<Father>
<FirstName>FFirstName</FirstName>
<LastName>FLastName</LastName>
<Age>35</Age>
</Father>
<Mother>
<FirstName>MFirstName</FirstName>
<LastName>MLastName</LastName>
<Age>33</Age>
</Mother>
</ParentName>
</ParentRoot>
儿童.xml
<ChildrenRoot>
<Child>
<FirstName>Child1FirstName</FirstName>
<LastName>Child1LastName</LastName>
<Age>14</Age>
</Child>
<Child>
<FirstName>Child2FirstName</FirstName>
<LastName>Child2LastName</LastName>
<Age>10</Age>
</Child>
</ChildrenRoot>
家庭.xml
<FamilyRoot>
<ParentName>
<Father>
<FirstName>FFirstName</FirstName>
<LastName>FLastName</LastName>
<Age>35</Age>
</Father>
<Mother>
<FirstName>MFirstName</FirstName>
<LastName>MLastName</LastName>
<Age>33</Age>
</Mother>
</ParentName>
<TotalChildren>2</TotalChildren>
<ChildrenCollection>
<Child>
<FirstName>Child1FirstName</FirstName>
<LastName>Child1LastName</LastName>
<Age>14</Age>
</Child>
<Child>
<FirstName>Child2FirstName</FirstName>
<LastName>Child2LastName</LastName>
<Age>10</Age>
</Child>
</ChildrenCollection>
</FamilyRoot>
解决方案
首先我认为你最好将两个xml资源合并为一个xml作为逻辑应用程序中的资源,如下所示:
<root>
<ParentRoot>
<ParentName>
<Father>
<FirstName>FFirstName</FirstName>
<LastName>FLastName</LastName>
<Age>35</Age>
</Father>
<Mother>
<FirstName>MFirstName</FirstName>
<LastName>MLastName</LastName>
<Age>33</Age>
</Mother>
</ParentName>
</ParentRoot>
<ChildrenRoot>
<Child>
<FirstName>Child1FirstName</FirstName>
<LastName>Child1LastName</LastName>
<Age>14</Age>
</Child>
<Child>
<FirstName>Child2FirstName</FirstName>
<LastName>Child2LastName</LastName>
<Age>10</Age>
</Child>
</ChildrenRoot>
</root>
然后我写了一个xsl代码来转换xml供你参考:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="FamilyRoot">
<xsl:element name="ParentName">
<xsl:element name="Father">
<xsl:element name="FirstName">
<xsl:value-of select="root/ParentRoot/ParentName/Father/FirstName" />
</xsl:element>
<xsl:element name="LastName">
<xsl:value-of select="root/ParentRoot/ParentName/Father/LastName" />
</xsl:element>
<xsl:element name="Age">
<xsl:value-of select="root/ParentRoot/ParentName/Father/Age" />
</xsl:element>
</xsl:element>
<xsl:element name="Mother">
<xsl:element name="FirstName">
<xsl:value-of select="root/ParentRoot/ParentName/Father/FirstName" />
</xsl:element>
<xsl:element name="LastName">
<xsl:value-of select="root/ParentRoot/ParentName/Father/LastName" />
</xsl:element>
<xsl:element name="Age">
<xsl:value-of select="root/ParentRoot/ParentName/Father/Age" />
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:element name="TotalChildren">
<xsl:value-of disable-output-escaping="yes" select="count(//Child)"/>
</xsl:element>
<xsl:element name="ChildrenCollection">
<xsl:for-each select="root/ChildrenRoot/Child">
<xsl:element name="Child">
<xsl:element name="FirstName">
<xsl:value-of select="FirstName" />
</xsl:element>
<xsl:element name="LastName">
<xsl:value-of select="LastName" />
</xsl:element>
<xsl:element name="Age">
<xsl:value-of select="Age" />
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
之后,我们可以将上面的 xsl 代码作为地图上传到集成帐户,并使用逻辑应用中的“转换 XML ”操作来转换 xml 资源。
希望对你的问题有所帮助~
推荐阅读
- android - 为什么扩展工厂不起作用?有任何想法吗?
- swift - SwiftUI 创建以点为指标的图像滑块
- python - 当字符串索引是整数时,“字符串索引必须是整数错误”
- r - 如何从geom_point中去掉图例,将两条平滑线的线型图例移到图形内部
- macos - 更新到 MacOs Catalina 使 Apple 脚本无法导出 Pages Document:“Pages got an error: Invalid key form”。
- assembly - 操作系统如何阻止程序访问内存?
- linux - 如何将多行文本传递给参数中的命令?
- visual-studio-code - vscode视图中的列表?
- javascript - res.send() 方法未定义发送到服务器的数据
- ios - 动态选择要在表格中编辑的部分