Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用XSLT复制XML并添加到现有文本_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

如何使用XSLT复制XML并添加到现有文本

如何使用XSLT复制XML并添加到现有文本,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我正在处理一个XML文件,其中需要添加一些花括号。我已经在使用XSLT(1.0)生成XML文件。缺少的唯一字符是XML文件中值周围的{} 源文件如下所示 <?xml version='1.0' encoding='utf-8'?> <container> <pan> <id>1</id> <input> <url>thisfile-1.xml</url> <

我正在处理一个XML文件,其中需要添加一些花括号。我已经在使用XSLT(1.0)生成XML文件。缺少的唯一字符是XML文件中值周围的{}

源文件如下所示

<?xml version='1.0' encoding='utf-8'?>
<container>
  <pan>
    <id>1</id>
    <input>
      <url>thisfile-1.xml</url>
    </input>
    <output>
      <url>thisoutput-1.txt</url>
    </output>
  </pan>
  <pan>
    <id>2</id>
    <input>
      <url>anotherfile-2.xml</url>
    </input>
    <output>
      <url>oldoutput-2.txt</url>
    </output>
  </pan>
  <pan>
    <id>3</id>
    <input>
      <url>alsofile-3.xml</url>
    </input>
    <output>
      <url>newoutput-3.txt</url>
    </output>
  </pan>
</container>

1.
thisfile-1.xml
thisoutput-1.txt
2.
另一个文件-2.xml
oldoutput-2.txt
3.
alsofile-3.xml
newoutput-3.txt
我需要更改的变量位于container/pan/input/url中 生成的文件应该如下所示

<?xml version='1.0' encoding='utf-8'?>
<container>
  <pan>
    <id>1</id>
    <input>
      <url>{thisfile-1.xml}</url>
    </input>
    <output>
      <url>thisoutput-1.txt</url>
    </output>
  </pan>
  <pan>
    <id>2</id>
    <input>
      <url>{anotherfile-2.xml}</url>
    </input>
    <output>
      <url>oldoutput-2.txt</url>
    </output>
  </pan>
  <pan>
    <id>3</id>
    <input>
      <url>{alsofile-3.xml}</url>
    </input>
    <output>
      <url>newoutput-3.txt</url>
    </output>
  </pan>
</container>

1.
{thisfile-1.xml}
thisoutput-1.txt
2.
{anotherfile-2.xml}
oldoutput-2.txt
3.
{alsofile-3.xml}
newoutput-3.txt
url是可变的,只应更改输入url,而不应更改输出url

我尝试了一些字符串替换示例,但实际上它们正在替换内容,我只想保留内容并添加大括号。 如果你有任何想法,我都会很感激的,我现在已经走到了死胡同了

我现在使用的XSLT是

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="no" indent="yes"/>

  <xsl:strip-space elements="*"/>

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

  <xsl:template match="input/url/text()">
    <xsl:text>replacetext</xsl:text>
  </xsl:template>

</xsl:stylesheet>

替换文本
这仅替换输入url。。。。
这就是我对XSLT的了解。

您已经做好了一切准备。换衣服

<xsl:text>replacetext</xsl:text>

啊,太好了,不知道concat()函数,很好,工作起来很有魅力,非常感谢。你救了我一天!
<xsl:value-of select="concat('{', ., '}')"/>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="no" indent="yes"/>

  <xsl:strip-space elements="*"/>

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

  <xsl:template match="input/url/text()">
    <xsl:value-of select="concat('{', ., '}')"/>
  </xsl:template>

</xsl:stylesheet>