2016-04-15 14 views
0

XSLT1.0を作成して以下のように出力する方法を教えてもらえますか? <csvImportSchema> <payload> <test>**COPY VALUE**</test> <test2>2</test2> <test3>3</test3> <ean>1111111111</ean> <productId/> </payload> </csvImportSchema>XSLTを使用して1つのノード値をコピーして新しいノードを作成する

<csvImportSchema> <payload> <test>COPY VALUE</test> <test2>2</test2> <test3>3</test3> <ean>1111111111</ean> <productId/> **<copied>COPY VALUE</copied>** </payload> <csvImportSchema>

答えて

0

次のXSLTは<payload>タグの端部に**コピーそれ間COPY VALUE文字列を抽出します。その後、COPY VALUEの前後の文字列が<copied>タグの接頭辞と接尾辞として使用されます。

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 

<xsl:template match="node()|@*"> 
    <xsl:copy> 
    <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="payload"> 
    <xsl:variable name="copyval" select="substring-before(substring-after(test/text(),'**'),'**')" /> 
    <xsl:variable name="valBefore" select="substring-before(test/text(),$copyval)" /> 
    <xsl:variable name="valAfter" select="substring-after(test/text(),$copyval)" /> 
    <xsl:copy> 
     <test><xsl:value-of select="$copyval" /></test> 
     <xsl:apply-templates select="node()[not(self::test)]|@*" /> 
     <xsl:value-of select="$valBefore" /><copied><xsl:value-of select="$copyval" /></copied><xsl:value-of select="$valAfter" /> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 
+0

私はそれらのアスタリスクが実際にあるとは思わない。 'node()[not(self :: test)]'を使うと良いでしょう。必要に応じて。 –

+0

@ michael.hor257k:あなたの提案したより良い方法で私の答えを改善しました。アスタリスクについて:うん、私はそれについても疑問に思った。しかし、これは質問された質問であり、私はそれを与えられたように答えようとしました。もし作者がそれについてコメントしたら、必要に応じてこれらの行を簡単に削除することができます。 – zx485

関連する問題