Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
Xml XSLT从标签复制文本_Xml_Xslt - Fatal编程技术网

Xml XSLT从标签复制文本

Xml XSLT从标签复制文本,xml,xslt,Xml,Xslt,有这个XML吗 <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="albaran.xsl"?> <albaran> <articulo precio="1.23" unidades="3">Tornillos</articulo> <articulo precio="2.34" unidades="5">Ar

有这个XML吗

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="albaran.xsl"?>
<albaran>
   <articulo precio="1.23" unidades="3">Tornillos</articulo>
   <articulo precio="2.34" unidades="5">Arandelas</articulo>
   <articulo precio="3.45" unidades="7">Tuercas</articulo>
   <articulo precio="4.56" unidades="9">Alcayatas</articulo>
</albaran>  

托尼洛斯
阿兰德拉斯
图尔卡斯
阿尔卡亚塔斯
XSLT输出必须是一个名为“total”的属性,该属性乘以“unidades”*“precio”。因此,输出必须是,例如:

 <articulo total="3.69">Tornillos</articulo>
托尼洛斯 但是我无法复制“articulo”里面的文字,每次我都会得到“Tornillos”。。。这是我的XSLT:

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

<xsl:template match="albaran">
<xsl:copy>
  <xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="articulo">
<xsl:copy>
  <xsl:attribute name="total">
    <xsl:value-of select="@precio * @unidades"/>
  </xsl:attribute>
  <xsl:value-of select="//articulo"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

正在选择:

/
随时随地

articulo
抓住第一个articulo

更改为
,这是当前范围的值。当前范围已由
xsl:template
match
部分设置。您可以使用:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="albaran">
    <xsl:copy>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

<xsl:template match="articulo">
    <xsl:copy>
        <xsl:attribute name="total">
            <xsl:value-of select="@precio * @unidades"/>
        </xsl:attribute>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>