名前をハードコードせずに、単一のノードに複数の属性を追加しようとしています。XSLT:複数の属性を追加する
:私のXSLT(バージョン1.0)はこれまでのところ、このようになります<xml>
<Item Name="FooName1"
ID="1000"
Description="FooDescription1"
>
<BOM>
<Child Name="FooName2"
ID="2000"
Description="FooDescription2"
/>
<Child Name="FooName3"
ID="3000"
Description="FooDescription3"
/>
</BOM>
</Item>
</xml>
:私はこのような何かを見て出力XMLを希望
<bom>
<columns>
<column id="0">Name</column>
<column id="1">ID</column>
<column id="2">Description</column>
</columns>
<rows>
<row number="0" level="0" position="">
<cell column="0">FooName1</cell>
<cell column="1">1000</cell>
<cell column="2">FooDescription1</cell>
</row>
<row number="1" level="1" position="">
<cell column="0">FooName2</cell>
<cell column="1">2000</cell>
<cell column="2">FooDescription2</cell>
</row>
<row number="2" level="1" position="">
<cell column="0">FooName3</cell>
<cell column="1">3000</cell>
<cell column="2">FooDescription3</cell>
</row>
</rows>
</bom>
:入力XMLは次のようになります
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" indent="yes" encoding="utf-8"/>
<xsl:template match="bom">
<impxml>
<Item>
<xsl:apply-templates select="columns/column" />
</Item>
</impxml>
</xsl:template>
<xsl:template match="columns/column">
<!-- <xsl:value-of select="."/> Fetch all column values -->
<xsl:for-each select=".">
<xsl:attribute name="TEST">TEST</xsl:attribute>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<xsl:attribute name="">
は、1つのハードコードされた名前のみを受け入れます。 columns \ columnのすべての値を反復処理して、それらを属性として同じItemまたはChildノードに追加するにはどうすればよいですか?
私はXSLTの新機能ですから、ここではどんな入力/ヘルプもありがとうございます。ありがとうございました。
をあなたは 'てみました<のxsl:属性名= ""/>xsl:variable使用
@id
と@column
値を対応することで一致していますb "/>'? – Yunnosch属性名 'ItemNo'は2つの' child'要素のどこから来ますか? –
@TimC:混乱して申し訳ありません、それは 'Description'だったはずです。 「ItemNo」はタイプミスでした。私はこれを修正しました。ありがとうございます。 – georgekw