Passer des paramètres aux XSLT
Il est possible de passer des variables à un programme XSLT depuis un script ANT.
Exemple : Côté ANT
CTRL+C pour copier, CTRL+V pour coller
1
2
<project xmlns:bib="http://bibtexml.sf.net/" xmlns:op="utc.fr:ics/opale3" basedir="." name="ref">
3
<xslt in="../out.xml" xslresource="../XSL/OneBibXMLToOpaleXml.xsl" out="../out1.xml">
4
<param name="Position" expression="1"/>
5
</xslt>
6
<xslt in="../out.xml" xslresource="../XSL/OneBibXMLToOpaleXml.xsl" out="../out5.xml">
7
<param name="Position" expression="5"/>
8
</xslt>
9
</project>
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:bib="http://bibtexml.sf.net/" xmlns:op="utc.fr:ics/opale3" basedir="." name="ref"> <xslt in="../out.xml" xslresource="../XSL/OneBibXMLToOpaleXml.xsl" out="../out1.xml"> <param name="Position" expression="1"/> </xslt> <xslt in="../out.xml" xslresource="../XSL/OneBibXMLToOpaleXml.xsl" out="../out5.xml"> <param name="Position" expression="5"/> </xslt> </project>
Exemple : Côté XSLT
CTRL+C pour copier, CTRL+V pour coller
1
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
3
xmlns:bib="http://bibtexml.sf.net/"
4
xmlns:op="utc.fr:ics/opale3">
5
6
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>
7
<xsl:param name="Position"/>
8
<xsl:template match="bib:file">
9
<xsl:for-each select="bib:entry">
10
<xsl:if test="position()=$Position">
11
<sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
12
<op:bib xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive" xmlns:op="utc.fr:ics/opale3">
13
<op:bibM>
14
</op:bibM>
15
</op:bib>
16
</sc:item>
17
</xsl:if>
18
</xsl:for-each>
19
</xsl:template>
20
21
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:bib="http://bibtexml.sf.net/" xmlns:op="utc.fr:ics/opale3"> <xsl:output encoding="UTF-8" method="xml" indent="yes"/> <xsl:param name="Position"/> <xsl:template match="bib:file"> <xsl:for-each select="bib:entry"> <xsl:if test="position()=$Position"> <sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core"> <op:bib xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive" xmlns:op="utc.fr:ics/opale3"> <op:bibM> </op:bibM> </op:bib> </sc:item> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>
On passe donc un paramètre à l'aide de :
<param name="Position" expression="5"/>
On le récupère dans le XSLT à l'aide de :
<xsl:param name="Position"/>
C'est utilisé dans l'exemple pour faire un test de position avec
<xsl:if test="position()=$Position">