使用XSL将XML从Get转换为AddChange
我试图用XSL转换XML,但我不知道它出了什么问题。目标XML中的字段名称不同,结构也略有不同。另外..如果我发出get请求并收到下面的xml,是否可以使用AddChange操作将其转换为xml使用XSL将XML从Get转换为AddChange,xml,xslt,Xml,Xslt,我试图用XSL转换XML,但我不知道它出了什么问题。目标XML中的字段名称不同,结构也略有不同。另外..如果我发出get请求并收到下面的xml,是否可以使用AddChange操作将其转换为xml <?xml version="1.0" encoding="UTF-8"?> <RegisterSearch TotalResults="149"> <SearchResults> <Document DocumentId="xxxxxxxxxxxxx"&g
<?xml version="1.0" encoding="UTF-8"?>
<RegisterSearch TotalResults="149">
<SearchResults>
<Document DocumentId="xxxxxxxxxxxxx">
<DocumentNumber>yyyyyyyyyyyyyyyy</DocumentNumber>
<Title>Test Title</Title>
</Document>
</SearchResults>
</RegisterSearch>
YYYYYYYYYYYYYY
考试题目
我的XSL文件是:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="SearchResults"/>
</xsl:template>
<xsl:template match="SearchResults">
<xsl:apply-templates select="Document"/>
</xsl:template>
<xsl:template match="Document">
<Ext_DB_STG class="R">
<xsl:apply-templates select="mro:SITEID"/>
<xsl:apply-templates select="mro:TASKID"/>
<xsl:apply-templates select="mro:WONUM"/>
</Ext_DB_STG>
</xsl:template>
<!-- <xsl:template match="WORKORDER.> -->
<xsl:template match="mro:SITEID">
<DocumentId><xsl:value-of select="."/></DocumentId>
</xsl:template>
<xsl:template match="mro:TASKID">
<DocumentNumber><xsl:value-of select="."/></DocumentNumber>
</xsl:template>
<xsl:template match="mro:WONUM">
<Title><xsl:value-of select="."/></Title>
</xsl:template>
</xsl:stylesheet>
我做错了什么
我希望得到的结果如下:
<?xml version="1.0" encoding="UTF-8"?>
<MXITEMIN xmlns="http://www.mro.com/mx/integration" language="EN">
<Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" operation="Notify" event="1">
<SenderID type="MAXIMO" majorversion="6" minorversion="0" build="02" dbbuild="V600-76">EXTSYS1</SenderID>
<CreationDateTime>2005-08-15T14:28:06-05:00</CreationDateTime>
<RecipientID>MX</RecipientID>
<MessageID>11241304878859947</MessageID>
</Header>
<Content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MXITEM>
<ITEM action="AddChange">
<SITEID>001TEST</SITEID>
<TASKID>test item</TASKID>
<WONUM>1</WONUM>
</ITEM>
</MXITEM>
</Content>
</MXITEMIN>
EXTSYS1
2005-08-15T14:28:06-05:00
MX
11241304878859947
001测试
测试项目
1.
您可以使用以下XSLT-1.0代码来转换输入XML的某些部分:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mro="http://www.mro.com/mx/integration">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="MXITEMIN" namespace="http://www.mro.com/mx/integration">
<xsl:attribute name="language">EN</xsl:attribute>
<xsl:apply-templates select="RegisterSearch/SearchResults"/>
</xsl:element>
</xsl:template>
<xsl:template match="SearchResults">
<xsl:element name="Header" namespace="http://www.mro.com/mx/integration">
<xsl:attribute name="operation">Notify</xsl:attribute>
<xsl:attribute name="event">1</xsl:attribute>
<xsl:element name="SenderID" namespace="http://www.mro.com/mx/integration">
<xsl:attribute name="type">MAXIMO</xsl:attribute>
<xsl:attribute name="majorversion">6</xsl:attribute>
<xsl:attribute name="minorversion">0</xsl:attribute>
<xsl:attribute name="build">02</xsl:attribute>
<xsl:attribute name="dbbuild">V600-76</xsl:attribute>
</xsl:element>
<xsl:element name="CreationDateTime" namespace="http://www.mro.com/mx/integration">2005-08-15T14:28:06-05:00</xsl:element>
<xsl:element name="RecipientID" namespace="http://www.mro.com/mx/integration">MX</xsl:element>
<xsl:element name="MessageID" namespace="http://www.mro.com/mx/integration">11241304878859947</xsl:element>
</xsl:element>
<xsl:apply-templates select="Document"/>
</xsl:template>
<xsl:template match="Document">
<Content xmlns="http://www.mro.com/mx/integration">
<MXITEM>
<ITEM action="AddChange">
<SITEID><xsl:value-of select="..."/></SITEID>
<TASKID><xsl:value-of select="..."/></TASKID>
<WONUM><xsl:value-of select="..."/></WONUM>
</ITEM>
</MXITEM>
</Content>
</xsl:template>
</xsl:stylesheet>
EN
通知
1.
马克西莫
6.
0
02
V600-76
2005-08-15T14:28:06-05:00
MX
11241304878859947
其产出是:
<?xml version="1.0" encoding="UTF-8"?>
<MXITEMIN xmlns="http://www.mro.com/mx/integration" language="EN">
<Header operation="Notify" event="1">
<SenderID type="MAXIMO" majorversion="6" minorversion="0" build="02" dbbuild="V600-76"/>
<CreationDateTime>2005-08-15T14:28:06-05:00</CreationDateTime>
<RecipientID>MX</RecipientID>
<MessageID>11241304878859947</MessageID>
</Header>
<Content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mro="http://www.mro.com/mx/integration">
<MXITEM>
<ITEM action="AddChange">
<SITEID/>
<TASKID/>
<WONUM/>
</ITEM>
</MXITEM>
</Content>
</MXITEMIN>
2005-08-15T14:28:06-05:00
MX
11241304878859947
因此,您必须调整“…”表达式的
xsl:value以选择所需的值(输入XML中不存在)。名称空间基本上是正确的,但我想您毕竟必须调整它们。您的XSL名称空间是错误的。它应该是xmlns:xsl=”http://www.w3.org/1999/XSL/Transform“
。另外,您想要的结果XML看起来怎么样?@zx485请参见我的编辑please@zx485我还做了您建议的更改,现在出现了下一个错误:无法使用样式表查看XML输入。请更正错误,然后单击“刷新”按钮,或稍后重试。系统不支持指定的编码。处理资源时出错这很奇怪,因为它是正确的命名空间。然而,XSLT的一半似乎应该朝相反的方向工作:从输出到输入。如果我错了,请纠正我。我在想办法。我想做的是一个请求,它将返回一个结果列表。我想在我的应用程序上将该结果列表作为AddChange操作进行处理。所以我需要添加一个XSL转换,以便以我需要的格式接收响应!我还有两个问题..它接受其他两个值,但不接受文档ID的值。我应该如何引用该组件?在使用它之后,我想为每个synthax使用..因为xml将包含更多行。这是我想要使用的信息,我修改了您发送给我的内容,以便从收到的xml中获取字段。我找到了答案。答案是:)再次非常感谢!完成!再次感谢!