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应用模板不在同一行上_Xslt - Fatal编程技术网

XSLT应用模板不在同一行上

XSLT应用模板不在同一行上,xslt,Xslt,今天我有一个非常基本的问题。为什么所有元素的属性都不对齐 我期望的输出是 姓、名、DOB如果Bene_DOB不存在,则使用DOB DEP 这样地: 梅尔吉布森,1965-01-01 诺里斯,恰克 但我得到了: 诺里斯,吉布森,查克,梅尔 1965-01-01 12345-01 1965-01-01 12345-01 我有这个XML <?xml version='1.0' encoding='UTF-8'?> <wd:Report_Data xmlns:wd="urn:com.w

今天我有一个非常基本的问题。为什么所有元素的属性都不对齐

我期望的输出是 姓、名、DOB如果Bene_DOB不存在,则使用DOB DEP 这样地: 梅尔吉布森,1965-01-01 诺里斯,恰克

但我得到了:

诺里斯,吉布森,查克,梅尔

1965-01-01 12345-01

1965-01-01 12345-01

我有这个XML

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/BCBSLA_CR_OFAC_BENE">
<wd:Report_Entry>
<wd:BENE_ALL>
  <wd:Last_Name>Norris</wd:Last_Name>
  <wd:First_Name>Chuck</wd:First_Name>
  <wd:REF_ID>12345-01</wd:REF_ID>
</wd:BENE_ALL>      
  <wd:Last_Name>Gibson</wd:Last_Name>
  <wd:First_Name>Mel</wd:First_Name>
  <wd:REF_ID>12345-02</wd:REF_ID>
</wd:BENE_ALL>
<wd:BENE_PEOPLE>
  <wd:BENE_DOB>1965-01-02</wd:BENE_DOB>
  <wd:Ben_Ref_ID>12345-01</wd:Ben_Ref_ID>
</wd:BENE_PEOPLE>
<wd:BENE_PEOPLE>
  <wd:BENE_DOB>1955-01-10</wd:BENE_DOB>
  <wd:Ben_Ref_ID>12345-02</wd:Ben_Ref_ID>
</wd:BENE_PEOPLE>
<wd:DEP>
  <wd:DOB_Dep>1965-01-01</wd:DOB_Dep>   
  <wd:Dep_Ref_ID>12345-01</wd:Dep_Ref_ID>
</wd:DEP>
</wd:Report_Entry> 
以下是我的XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xsl"
                xmlns:wd="urn:com.workday.report/BCBSLA_CR_OFAC_BENE"
                version="2.0">


  <xsl:output method="text"/>


  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="wd:BENE_ALL">
    <xsl:apply-templates select="wd:EMPLID" mode="csv"/>
    <xsl:apply-templates select="wd:Last_Name" mode="csv"/>
    <xsl:apply-templates select="wd:First_Name" mode="csv"/>
  </xsl:template>


  <xsl:template match="wd:BENE_People">
    <xsl:apply-templates select="wd:DOB_Bene" mode="csv" />
  </xsl:template>


  <!--<xsl:choose>
      <xsl:when test=
    </xsl:choose>-->


  <xsl:template match="*" mode="csv">
    <xsl:value-of select="concat('&quot;', ., '&quot;,')" />
  </xsl:template>

  <xsl:template match="*" mode="csv-nl">
    <xsl:value-of select="concat('&quot;', ., '&quot;&#xA;')" />
  </xsl:template>

</xsl:stylesheet>

谢谢你的帮助

如果我正确理解了XML的结构,您需要为每组元素创建一个新的数据行,该行以姓氏开始。在XSLT 2.0中,这可以通过执行以下操作来实现:

<xsl:template match="/Report_Data">
    <xsl:for-each-group select="Report_Entry/BENE_ALL/*" group-starting-with="Last_Name">
        <xsl:value-of select="concat('&quot;', ., '&quot;,')" />
        <xsl:value-of select="concat('&quot;', current-group()[self::First_Name], '&quot;&#10;')" />
    </xsl:for-each-group>
</xsl:template>
要添加Bene_DOB值,您可以使用如下公式:

XSLT2.0

然后:

<xsl:template match="/Report_Data">
    <xsl:for-each-group select="Report_Entry/BENE_ALL/*" group-starting-with="Last_Name">
        <xsl:value-of select="my:quote(.), my:quote(current-group()[self::First_Name]), my:quote(key('person-dob', current-group()[self::REF_ID]))" separator=","/>
        <xsl:text>&#10;</xsl:text>
    </xsl:for-each-group>
</xsl:template>

演示:

您能发布一个包含多个wd:BENE_DOB和wd:DOB_Dep的示例吗?谢谢Michael-我用的值重写了它,这解决了我的项目不出现在一行上的问题。谢谢但是这个键对我不起作用,因为我有XSLT 1.0。@BWatkins您的原始样式表被标记为version=2.0,所以我假设这是您的处理器支持的。在任何情况下,键在XSLT1.0中都可以工作,但xsl:for each group不能。从更新的XML判断,您不需要它。
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="urn:com.workday.report/BCBSLA_CR_OFAC_BENE">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:key name="person-dob" match="BENE_DOB" use="following-sibling::Ben_Ref_ID[1]" />

<xsl:template match="/Report_Data">
    <xsl:for-each-group select="Report_Entry/BENE_ALL/*" group-starting-with="Last_Name">
        <xsl:value-of select="concat('&quot;', ., '&quot;,')" />
        <xsl:value-of select="concat('&quot;', current-group()[self::First_Name], '&quot;,')" />
        <xsl:value-of select="concat('&quot;', key('person-dob', current-group()[self::REF_ID]), '&quot;&#10;')" />
    </xsl:for-each-group>
</xsl:template>

</xsl:stylesheet>
<xsl:function name="my:quote">
    <xsl:param name="text"/> 
    <xsl:sequence select="concat('&quot;', $text, '&quot;')" />
</xsl:function>
<xsl:template match="/Report_Data">
    <xsl:for-each-group select="Report_Entry/BENE_ALL/*" group-starting-with="Last_Name">
        <xsl:value-of select="my:quote(.), my:quote(current-group()[self::First_Name]), my:quote(key('person-dob', current-group()[self::REF_ID]))" separator=","/>
        <xsl:text>&#10;</xsl:text>
    </xsl:for-each-group>
</xsl:template>