Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
Xslt 如何根据属性值对xsl:result文档输出设置条件_Xslt_Xslt 2.0 - Fatal编程技术网

Xslt 如何根据属性值对xsl:result文档输出设置条件

Xslt 如何根据属性值对xsl:result文档输出设置条件,xslt,xslt-2.0,Xslt,Xslt 2.0,我正在使用Saxon解析器转换XML。我必须在两个位置生成相同的输出,我可以这样做。我想设置这样的条件:如果count属性值为0,则它不应生成任何输出文件。我的输入文件是 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.or

我正在使用Saxon解析器转换XML。我必须在两个位置生成相同的输出,我可以这样做。我想设置这样的条件:如果count属性值为0,则它不应生成任何输出文件。我的输入文件是

             <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <soapenv:Body>
<ns1:getDocumentByKeyResponsexmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <Document xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
   <Attributes>
   <Attribute name="duration">0:00:00.789</Attribute>
   <Attribute name="count">0</Attribute>
    <Attribute name="entity">SourcingRequest</Attribute>
    <Attribute name="mode">XML</Attribute>
     <Attribute name="version">http://www.taleo.com/ws/tee800/2009/01</Attribute>
    </Attributes>
    <Content>
   <ExportXML xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07"/>
   </Content>
   </Document>
  </ns1:getDocumentByKeyResponse>
  </soapenv:Body>
  </soapenv:Envelope>
我的xsl文件是这样的

  <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output  indent="yes" encoding="utf-8"/>
     <xsl:strip-space elements="*"/>
     <xsl:param name="pDest" select="'file:///c:/temp/'"/>
     <xsl:param name="pDest1" select="'file:///c:/'"/>

  <xsl:template match="*:field">
     <xsl:element name="{lower-case(@name)}">
       <xsl:apply-templates/>    
     </xsl:element>
  </xsl:template>

  <xsl:template match="/">
     <xsl:result-document
            href="{$pDest}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
        <JobPositionPostings>
          <xsl:apply-templates select="descendant::*:Content[1]" />
        </JobPositionPostings>
     </xsl:result-document>
     <xsl:result-document
            href="{$pDest1}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
        <JobPositionPostings>
          <xsl:apply-templates select="descendant::*:Content[1]" />
        </JobPositionPostings>
     </xsl:result-document>
  </xsl:template>

  <xsl:template match="*:record">
  <!--doing rest operation if attribute count not equal to 0 -->
  </xsl:template> 

  </xsl:stylesheet>

我想你想替换模板

  <xsl:template match="/">
     <xsl:result-document
            href="{$pDest}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
        <JobPositionPostings>
          <xsl:apply-templates select="descendant::*:Content[1]" />
        </JobPositionPostings>
     </xsl:result-document>
     <xsl:result-document
            href="{$pDest1}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
        <JobPositionPostings>
          <xsl:apply-templates select="descendant::*:Content[1]" />
        </JobPositionPostings>
     </xsl:result-document>
  </xsl:template>
不知怎的

  <xsl:template match="/">
    <xsl:if test="soapenv:Envelope/soapenv:Body/ns1:getDocumentByKeyResponse/df:Document/df:Attributes/df:Attribute[@name = 'count'] != 0">
     <xsl:result-document
            href="{$pDest}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
        <JobPositionPostings>
          <xsl:apply-templates select="descendant::*:Content[1]" />
        </JobPositionPostings>
     </xsl:result-document>
     <xsl:result-document
            href="{$pDest1}requsition_{format-date(current-date(),'[D01]_[M01]')}.xml">
        <JobPositionPostings>
          <xsl:apply-templates select="descendant::*:Content[1]" />
        </JobPositionPostings>
     </xsl:result-document>
   </xsl:if>
  </xsl:template>
你在哪里额外申报

<xsl:stylesheet xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07"
  xmlns:df="http://www.taleo.com/ws/integration/toolkit/2005/07"
  exclude-result-prefixes="soapenv ns1 df"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">

这样,只有在条件为真时,才会执行您的两条xsl:result文档指令。

您的问题完全不清楚。当源文档中没有匹配的元素时,为什么有匹配*:记录和*:字段的模板规则?您希望模板中与*:record匹配的条件如何影响其他模板中的xsl:result文档调用?你想生产什么产品?我对这个问题投了反对票,因为它是不可理解的,而且你甚至都不愿意费心把你的代码清晰地格式化。谢谢你的回答。如果有一些值,那么我必须将平面xml转换为嵌套xml,所以唯一的条件是*:record。嵌套部分工作正常,我只想知道,如果计数值为0,则不应生成任何文件,否则它将执行这样的嵌套转换。是否可以在单个xsl转换中执行?