以下の期待される出力のような子供3と子供4の要素を形成する間、私は困難に直面していますが、運はありません。外部ソースからXSLTで助けが必要期待される結果として子ノードを形成するためのコード
入力メッセージ:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<PurchaseOrder id="aoi00037607">
<attr attr-name="A">
<new-value>adi00010210</new-value>
</attr>
<attr attr-name="B">
<new-value>99</new-value>
</attr>
<attr attr-name="C">
<new-value>active</new-value>
</attr>
<attr attr-name="D">
<new-value>
<child1>iop00010538</child1>
<child2>2</child2>
</new-value>
<new-value>
<child1>cid2313213</child1>
<child2>2</child2>
</new-value>
<new-value>
<child1>hri00075562</child1>
<child2>1</child2>
</new-value>
</attr>
<attr attr-name="E">
<new-value>
<materials type="required">
<material system="XXX">
<attr attr-name="child3">primary</attr>
<attr attr-name="child4">2</attr>
</material >
</materials>
</new-value>
</attr>
</PurchaseOrder>
XSLTコード上のXSLTで以下のコードは、任意の結果を与えていない
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn:demo:PurchaseOrder">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:key name="keyAttrName" match="attr" use="@attr-name" />
<xsl:template match="PurchaseOrder">
<ns0:PurchaseOrderMSG>>
<Orders>
<Order id="{@id}">
<xsl:for-each select="attr[generate-id() = generate-id(key('keyAttrName', @attr-name)[1])]">
<xsl:variable name="nodeName" select="@attr-name" />
<xsl:choose>
<xsl:when test="key('keyAttrName', @attr-name)/new-value/*/node()">
<xsl:for-each select="new-value">
<xsl:element name="{$nodeName}">
<xsl:copy-of select="*" />
</xsl:element>
</xsl:for-each>
</xsl:when>
<xsl:when test="key('keyAttrName', @attr-name)/new-value/materials/material">
<xsl:for-each select="key('keyAttrName', @attr-name)">
<xsl:element name="{$nodeName}">
<xsl:copy-of select="attr" />
</xsl:element>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="key('keyAttrName', @attr-name)">
<xsl:element name="{$nodeName}">
<xsl:value-of select="new-value" />
</xsl:element>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</Order>
</Orders>
</ns0:PurchaseOrderMSG>
</xsl:template>
</xsl:stylesheet>
を変換するために書かれた
<xsl:when test="key('keyAttrName', @attr-name)/new-value/materials/material">
<xsl:for-each select="key('keyAttrName', @attr-name)">
<xsl:element name="{$nodeName}">
<xsl:copy-of select="attr" />
</xsl:element>
</xsl:for-each>
</xsl:when>
期待される結果:修正する必要がある何
<?xml version="1.0" encoding="UTF-8"?>
<ns0:PurchaseOrderMSG xmlns:ns0="urn:demo:PurchaseOrder">
<Orders>
<Order>
<A>adi00010210</A>
<B>99</B>
<C>active </C>
<D>
<Child1>iop00010538</Child1>
<Child2>2</Child2>
</D>
<D>
<child1>cid2313213</child1>
<child2>2</child2>
</D>
<D>
<child1>hri00075562</child1>
<child2>1</child2>
</D>
<E>
<Materials type="required">
<Material system="XXXX">
<child3>primary</child3>
<child4>2</child4>
</Material>
</Materials>
</E>
</Order>
</Orders>
</ns0:PurchaseOrderMSG>
が期待される結果を得るために?参照用
リンク:
<xsl:when test="key('keyAttrName', @attr-name)/new-value/*/node()[not(name() = 'material')]">
からNeed help in forming target xml using XSLT
_actual_の出力は何ですか? –
記載されているXSLTコードが添付された出力を追加しました – piuser