Xml 使用XSLT4NODE添加节点

Xml 使用XSLT4NODE添加节点,xml,node.js,xslt,Xml,Node.js,Xslt,我使用的是XSLT4Node,但是在文档中我没有找到如何向节点添加更多子节点的信息。有人对此有想法吗 刚才我有: order.xml <order><book ISBN="10-861003-324"><title>The Handmaid's Tale</title><price>19.95</price></book><cd ISBN="2-3631-4"><title>America

我使用的是XSLT4Node,但是在文档中我没有找到如何向节点添加更多子节点的信息。有人对此有想法吗

刚才我有:

order.xml

<order><book ISBN="10-861003-324"><title>The Handmaid's Tale</title><price>19.95</price></book><cd ISBN="2-3631-4"><title>Americana</title><price>16.95</price>
  </cd>
</order>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="discount"/>
    <xsl:template match="/">
        <order>
            <xsl:variable name="sub-total" select="sum(//price)"/>
            <total>


    <xsl:value-of select="$sub-total"/>
        </total>15% discount if paid by: <xsl:value-of select="$discount"/>
    </order>
</xsl:template>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

    <order>
        <xsl:for-each select="catalog/cd">
            <albums>
                <title>
                    <xsl:value-of select="title"/>
                </title>
                <artist>
                    <xsl:value-of select="artist"/>
                </artist>
            </albums>
        </xsl:for-each>
    </order>


</xsl:template>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
</catalog>

如果可能,库允许插入多个参数并使用xls函数,如:
xsl:for each select=“catalog/cd”
标记,使用循环插入多个值

index.js

var xslt4node = require('xslt4node');

var config = {
        xsltPath: 'discount.xsl',
        sourcePath: 'order.xml',
        result: 'result.xml',
        params: {
            adiscount: '2014/08/02'
        },
        props: {
            indent: 'yes'
        }
    };

xslt4node.transform(config, function (err) {
            if (err) {
                console.log(err);
            }
            finishRequest(  response , "done" );
        });
var xslt4node = require('xslt4node');

var config = {
        xsltPath: 'discount.xsl',
        sourcePath: 'order.xml',
        result: 'result.xml',
        props: {
            indent: 'yes'
        }
    };
折扣。xsl

<order><book ISBN="10-861003-324"><title>The Handmaid's Tale</title><price>19.95</price></book><cd ISBN="2-3631-4"><title>Americana</title><price>16.95</price>
  </cd>
</order>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="discount"/>
    <xsl:template match="/">
        <order>
            <xsl:variable name="sub-total" select="sum(//price)"/>
            <total>


    <xsl:value-of select="$sub-total"/>
        </total>15% discount if paid by: <xsl:value-of select="$discount"/>
    </order>
</xsl:template>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

    <order>
        <xsl:for-each select="catalog/cd">
            <albums>
                <title>
                    <xsl:value-of select="title"/>
                </title>
                <artist>
                    <xsl:value-of select="artist"/>
                </artist>
            </albums>
        </xsl:for-each>
    </order>


</xsl:template>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
</catalog>

order.xml

<order><book ISBN="10-861003-324"><title>The Handmaid's Tale</title><price>19.95</price></book><cd ISBN="2-3631-4"><title>Americana</title><price>16.95</price>
  </cd>
</order>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="discount"/>
    <xsl:template match="/">
        <order>
            <xsl:variable name="sub-total" select="sum(//price)"/>
            <total>


    <xsl:value-of select="$sub-total"/>
        </total>15% discount if paid by: <xsl:value-of select="$discount"/>
    </order>
</xsl:template>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

    <order>
        <xsl:for-each select="catalog/cd">
            <albums>
                <title>
                    <xsl:value-of select="title"/>
                </title>
                <artist>
                    <xsl:value-of select="artist"/>
                </artist>
            </albums>
        </xsl:for-each>
    </order>


</xsl:template>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
隐藏你的心
邦尼泰勒
英国
哥伦比亚唱片公司
9.90
1988
最成功的
多莉·帕顿
美国
RCA
9.90
1982