Perl XSLT中的外部脚本
我有下面的XML文件,以及如何在XSLT中调用Perl XSLT中的外部脚本,perl,xslt,Perl,Xslt,我有下面的XML文件,以及如何在XSLT中调用perl脚本。因为我想更新每个条目的id。例如,下一个条目应该是这样的 我的XML是: <feed> <author> <firstName>f</firstName> <lastName>l</lastName> </author> <date>2011-01-02 </date> <entry>
perl
脚本。因为我想更新每个条目的id
。例如
,下一个条目应该是这样的
我的XML是:
<feed>
<author>
<firstName>f</firstName>
<lastName>l</lastName>
</author>
<date>2011-01-02 </date>
<entry>
<id>1</id>
<Name>aaa</Name>
<Content>XXX</Content>
</entry>
<entry>
<id>2</id>
<Name>bbb</Name>
<Content>YYY</Content>
</entry>
</feed>
F
L
2011-01-02
1.
aaa
XXX
2.
bbb
YYY
我的XSLT是:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="updateItems" select="feed/entry" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="feed">
<xsl:copy>
<xsl:apply-templates select="@* | node()[not(self::entry)] | entry[not(id = $updateItems/id)]" />
<xsl:apply-templates select="$updateItems" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
首先,我认为不可能调用Perl脚本来处理XSLT中的XML数据。如果您使用Saxon(我想您这样做是因为您使用XSLT2.0),那么您可以以某种方式使用Java类 但是,如果我正确理解您的需求,就不需要使用外部编程语言。据我所知,您只需要将ID乘以5即可更改ID。所以,我建议你这样做:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 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:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="id">
<xsl:copy><xsl:value-of select=". * 5"/></xsl:copy>
</xsl:template>
</xsl:stylesheet>
除了id元素的文本值乘以5外,这个脚本不涉及任何内容。就这样。它工作得很好。但是如何添加
属性
而不是元素
?而且不可能在XSLT
中调用外部脚本?