xsltを使用してxmlsを変換し、Receipt/Process ノードを反復し、ノードにタイプ属性を追加します。ノードの値に基づいて、string/int/floatになります。 その部分は正常に動作します。xsltを使用してノードの名前をノードの名前に変更します。
"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>
"MainMedia"から "Source"の場合は "Input"ノードの値を変更したいだけですが、それだけです。
ありがとうございます。
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>
あなたは私たちに多くの重要なことを見せてくれませんでした。 2)変換が実装しなければならない要件。質問を編集してこれらを提供してください。あなたの心を読むことはできません。また、あなたが提供したコードは、あなたの要求に矛盾しています(あなたの要求に反します)。どのように 'type'属性が生成されるべきですか? –
こんにちはDimitre、私はポストを更新しました。よろしく、 –
ありがとう、ガボール。私の答えを見てください。 –