2017-06-28 30 views
0

を使用してタグの値にパラメータを追加XSLTを使用してファイルには、出力XMLは、私は以下のXSLTを使用しています。この私は、XML以下のように持っているXSLT

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<properties> 
<entry key="user">1234</entry> 
<entry key="docname">abc_1.pdf</entry> 
</properties> 

ようにする必要があります。パラメータidがjavaコードから渡されています。

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> 
<xsl:param name="id"/> 
    <xsl:variable name="newName" select="/properties/entry[@key='docname']"/> 
    <xsl:template match="entry[@key='docname']"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*"/> 
     <xsl:value-of select="replace($newName, $newName, $id)"/> 
    </xsl:copy> 
    </xsl:template> 

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

上記のxsltは、docnameタグの値を置き換えます。全体の値を置き換える代わりに、拡張子(abc_1.pdf)の前にアンダースコアを付けてIDを追加したいとします。 誰かがこれを手伝ってくれますか?

+0

したがって、 'id'パラメータの文字列' _1'または '1'だけでどの値を渡しますか? –

+0

idパラメータに値1を渡しています –

答えて

1

入力データの複雑さに依存します。これらのファイル名に、あなたは、単に

<xsl:value-of select="concat(substring-before(., '.'), '_', $id, '.', substring-after(., '.'))"/> 

をするか、または_の連結、$idと接尾辞最後にサフィックスを置き換えるために

<xsl:value-of select="replace(., '\.\w+$', concat('_', $id, '$0'))"/> 

を使用することができます。

関連する問題