Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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中的x函数?_Xml_Xslt - Fatal编程技术网

Xml XSLT中的x函数?

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

在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/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>