xsltを使用してxmlファイルを別のxmlファイルに変換する必要があります。 入力ファイルは以下の通りである:XML変換
<root type="object">
<items type="array">
<item type="object">
<updated_at type="string">2017-05-20</updated_at>
<external_id type="null"></external_id>
<created_at type="string">2017-05-20</created_at>
<embed_code type="string">ec111</embed_code>
<status type="string">live</status>
<content_type type="string">video</content_type>
<name type="string"></name>
<hosted_at type="null"></hosted_at>
</item>
<item type="object">
<updated_at type="string">2017-05-19</updated_at>
<external_id type="null"></external_id>
<labels type="array">
<item type="object">
<name type="string">lbl name 1</name>
<full_name type="string">full lbl name 1</full_name>
<id type="string">lbl1</id>
<parent_id type="string">parent_id_1</parent_id>
</item>
</labels>
<created_at type="string">2017-05-20</created_at>
<embed_code type="string">ec112</embed_code>
<status type="string">live</status>
<content_type type="string">video</content_type>
<name type="string">test</name>
<hosted_at type="null"></hosted_at>
</item>
<item type="object">
<updated_at type="string">2017-05-19</updated_at>
<external_id type="null"></external_id>
<labels type="array">
<item type="object">
<name type="string">lbl name 2</name>
<full_name type="string">full lbl name 2</full_name>
<id type="string">lbl2</id>
<parent_id type="string">parent_id_2</parent_id>
</item>
<item type="object">
<name type="string">lbl name 3</name>
<full_name type="string">full lbl name 3</full_name>
<id type="string">lbl3</id>
<parent_id type="string">parent_id_3</parent_id>
</item>
</labels>
<created_at type="string">2017-05-20</created_at>
<embed_code type="string">ec113</embed_code>
<status type="string">live</status>
<content_type type="string">video</content_type>
<name type="string">testing</name>
<hosted_at type="null"></hosted_at>
</item>
</items>
</root>
は以下のフォーマットに上記のXMLを変換する必要があります
<?xml version="1.0"?>
<labels>
<item>
<embed_code>ec112</embed_code>
<name>lbl name 1</name>
<full_name>full lbl name 1</full_name>
<id>lbl1</id>
<parent_id>parent_id_1</parent_id>
</item>
<item>
<embed_code>ec113</embed_code>
<name>lbl name 2</name>
<full_name>full lbl name 2</full_name>
<id>lbl2</id>
<parent_id>parent_id_2</parent_id>
</item>
<item>
<embed_code>ec113</embed_code>
<name>lbl name 3</name>
<full_name>full lbl name 3</full_name>
<id>lbl3</id>
<parent_id>parent_id_3</parent_id>
</item>
</labels>
パスルート/アイテム/アイテムがembed_codeタグを有するであろう。同じパスにラベルノードがあるか、ラベルがない可能性があります。ラベルには1つ以上のアイテムが含まれている場合があります。次のように
変換ルールがある
: 1)は、ラベルとその子 2を取得する必要があります)すべての属性 3を取り外して)各ラベル/項目ノードの下にembed_codeノードを持参、これまでに私のコードです:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="item">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
<xsl:template match="/">
<labels>
<xsl:for-each select="root/items/item">
<xsl:variable name="eCode" select="embed_code"/>
<xsl:for-each select="labels/*">
<item>
<embed_code>
<xsl:value-of select="$eCode"/>
</embed_code>
<xsl:for-each select="root/items/item/labels/item/*">
</xsl:for-each>
</item>
</xsl:for-each>
</xsl:for-each>
</labels>
</xsl:template>
<xsl:template match="@*" />
</xsl:stylesheet>
ラベル/アイテムの子ノードを取得できません。これについて私を助けてください。
おかげ
スタックオーバーフローに作業割り当てをダンプしないでください。あなた自身の仕事をしてください。現在作成しているXSLTスタイルシートについて質問がある場合は、コードを投稿して特定の質問をしてください。お手伝いします。 – Tomalak
これまで私のxslt作業を含むように投稿を編集しました。ラベル/項目の子ノードを持っていきたい –
それは良いです。常にあなたのコードと問題の説明を含めてください。 – Tomalak