Xml XSLT中的x函数?
在XSLT(for函数)中是否有方法循环使用文件名 我想检查文件是否存在于从_001.jpg…到_005.jpg 目前我可以检查一个文件:Xml XSLT中的x函数?,xml,xslt,Xml,Xslt,在XSLT(for函数)中是否有方法循环使用文件名 我想检查文件是否存在于从_001.jpg…到_005.jpg 目前我可以检查一个文件: <xsl:stylesheet exclude-result-prefixes="xs fs" version="2.0" xmlns:fs="java.io.File" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Trans
<xsl:stylesheet exclude-result-prefixes="xs fs" version="2.0" xmlns:fs="java.io.File" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output cdata-section-elements="DESCRIPTION" indent="yes" method="xml"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="product">
<xsl:apply-templates/>
<xsl:variable name="imageproductid" select="code"/>
<xsl:choose>
<xsl:when test="fs:exists(fs:new(concat('/images/',$imageproductid,'_001.jpg')))">
<IMAGE1>
<xsl:value-of select="concat('/images/',$imageproductid,'_001.jpg')"/>
</IMAGE1>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
其中
标记应为,,,
我使用的是Saxon 9.1、XSLT 2.0。使用可选的
符号在一组整数上循环:
<xsl:for-each select="1 to 5">
... '.' will be an integer from 1 to 5 here
</xsl:for-each>
要创建正确命名的新元素,请使用
:
这是完美的:快速和简单。
... fs:exists(fs:new(concat('/images/',$imageproductid,'_00', ., '.jpg')
<xsl:element name="{concat('IMAGE', .)}">
.. <IMAGEx> contents ..
</xsl:element>
<xsl:template match="product">
<xsl:apply-templates />
<xsl:variable name="imageproductid" select="code" />
<xsl:for-each select="1 to 5">
<xsl:variable name="filename"
select="concat('/images/',$imageproductid,'_00', ., '.jpg')" />
<xsl:if test="fs:exists(fs:new($filename))">
<xsl:element name="{concat('IMAGE', .)}">
<xsl:value-of select="$filename" />
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>