以下の xslt を使用して xml を変換します。これは Receipt/Process ノードを反復処理し、タイプ属性をノードに追加します。ノードの値に基づいて、string/int/float になります。その部分はうまく機能します。
また、「Node」ノードの名前を「Node」に変更し、そのインデックスを連結して、「Name」ノードの値となる属性を追加する必要があります。
次のようなものに変換したい複数の「ノード」がある場合があります。
「Cuda3DLut」が来る最初のノード<Name>Cuda3DLut</Name>
<Node1 type="Cuda3DLut" >
<Input type="ToolLink" role="Input" format="red,green,blue">Source</Input>
<Lut type="string">Identity</Lut>
<Output type="ToolLink" role="Output" format="red,green,blue">RESULT1</Output>
<bypass type="int">0</bypass>
<nodeRole type="string">viewing</nodeRole>
<nodeShortName type="string">LUT</nodeShortName>
</Node1>
2 番目のノード
<Node2 type="CudaTool" >
...
</Node2>
また、「Input」ノードの値が「MainMedia」の場合は「Source」に変更したいと思いますが、その場合のみです。
どうもありがとう。
Source XML:
<Receipt>
<Process>
<Node>
<Name>Cuda3DLut</Name>
<Input>MainMedia</Input>
<Lut>Identity</Lut>
<Output>RESULT1</Output>
<bypass>0</bypass>
<nodeRole>viewing</nodeRole>
<nodeShortName>LUT</nodeShortName>
</Node>
<Node>
<Name>CudaTool</Name>
<Input>MainMedia</Input>
<Lut>Identity</Lut>
<Output>RESULT1</Output>
<bypass>0</bypass>
<nodeRole>viewing</nodeRole>
<nodeShortName>LUT</nodeShortName>
</Node>
</Process>
<Encode>
<Job>
...
</Job>
</Encode>
</Receipt>
xslt:
<?xml version="1.0"?>
<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="/">
<cut>
<xsl:apply-templates/>
</cut>
</xsl:template>
<xsl:template match="Process">
<xsl:for-each select="Node/*">
<xsl:choose>
<xsl:when test="name() = 'Input'">
<xsl:copy>
<xsl:attribute name="type">ToolLink</xsl:attribute>
<xsl:attribute name="role">Input</xsl:attribute>
<xsl:attribute name="format">red,green,blue</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:when>
<xsl:when test="name() = 'Output'">
<xsl:copy>
<xsl:attribute name="type">ToolLink</xsl:attribute>
<xsl:attribute name="role">Output</xsl:attribute>
<xsl:attribute name="format">red,green,blue</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<!-- Add type attribute to the node based on its value -->
<xsl:choose>
<xsl:when test="number(.) = .">
<xsl:choose>
<xsl:when test="contains(., '.')">
<xsl:copy>
<xsl:attribute name="type">float</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:attribute name="type">int</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:attribute name="type">string</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template match="Encode">
</xsl:template>
</xsl:stylesheet>