2017-06-20 31 views
1
<?xml version='1.0' encoding='UTF-8'?> 
    <wd:Report_Data 
    xmlns:wd="urn:com.workday.report/CIS_CR_INT122_HMS_Dependent_Report"> 
    <wd:Report_Entry> 
    <wd:Dependents> 
    <wd:project_id>2269</wd:project_id> 
    <wd:plan_id>5909</wd:plan_id> 
    <wd:employee_client_id>JA5637</wd:employee_client_id> 
    </wd:Dependents> 
    </wd:Report_Entry> 
    <wd:Report_Entry> 
     <wd:Dependents> 
       <wd:project_id>2269</wd:project_id> 
       <wd:plan_id>5909</wd:plan_id> 
       <wd:employee_client_id>JA4345</wd:employee_client_id> 
     </wd:Dependents> 
    </wd:Report_Entry> 
    <wd:Report_Entry> 
     <wd:Dependents> 
       <wd:project_id>2269</wd:project_id> 
       <wd:plan_id>5909</wd:plan_id> 
       <wd:employee_client_id>JA5637</wd:employee_client_id> 
     </wd:Dependents> 
     </wd:Report_Entry> 
     </wd:Report_Data> 

XLST不工作。它不显示,分隔符或换行。我还需要删除重复的employee_client_id。前JA5637来了两次,我需要删除使用XSLT。每个依赖关系都应该放在一个带有逗号分隔符的新行中。见下文XSLT 2.0转换

样品XSLT我建

输出
  <?xml version="1.0" encoding="UTF-8"?> 
     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     exclude-result-prefixes="xs" 
     version="2.0"> 

      <xsl:strip-space elements="*"/>  
      <xsl:variable name="NEWLINE"> 
      <xsl:text>&#13;&#10;</xsl:text> 
      </xsl:variable> 
      <xsl:variable name="DELIMITER">,</xsl:variable> 
      <xsl:output method="text"/> 

      <xsl:template match="wd:Report_Data" 
       xmlns:wd="urn:com.comday.report/INT007BOutbound"> 
       <!--These are just text column headers for output--> 
       <xsl:text>project_id,plan_id,employee_client_id</xsl:text> 
       <xsl:value-of select="$NEWLINE"/> 
       <xsl:for-each select="wd:Report_Entry"> 
       <xsl:for-each select="wd:Dependents"> 
       <xsl:value-of select="wd:project_id"/> 
       <xsl:value-of select="$DELIMITER"/> 
       <xsl:text>&#xA;</xsl:text> 
       <xsl:value-of select="wd:plan_id"/> 
       <xsl:value-of select="$DELIMITER"/> 
       <xsl:text>,</xsl:text> 
        <xsl:value-of select="wd:employee_client_id"/> 
        </xsl:for-each> 
        <xsl:value-of select="$NEWLINE"/> 
        <xsl:text>&#xA;</xsl:text> 
        </xsl:for-each> 
        </xsl:template> 
       </xsl:stylesheet> 

输出

项目-ID,plan_id的数据类型,employee_client_id

2269,5909,JA5637

2269,5909,JA4345

回答

0

您的XML声明:

xmlns:wd="urn:com.workday.report/CIS_CR_INT122_HMS_Dependent_Report" 

,但你这样做:

xmlns:wd="urn:com.comday.report/INT007BOutbound" 

其结果是,你的模板不匹配输入XML东西,并通过built-in template rules产生你看到整个输出。


我没有检查你的样式表的其余部分。不过,我想补充一点,在XSLT 2.0中,您可以使用xpath-default-namespace而不是前缀。

1

是的,我得到了它

<xsl:strip-space elements="*"/>  
<xsl:variable name="NEWLINE"> 
    <xsl:text>&#13;&#10;</xsl:text> 
</xsl:variable> 
<xsl:variable name="DELIMITER">,</xsl:variable> 
<xsl:output method="text"/> 

<xsl:template match="wd:Report_Data" xmlns:wd="urn:com.workday.report/CIS_CR_INT122_HMS_Dependent_Report"> 
    <!--These are just text column headers for output--> 
    <xsl:text>project_id,plan_id,employee_client_id</xsl:text> 
    <xsl:value-of select="$NEWLINE"/> 
    <xsl:for-each-group select="wd:Report_Entry/wd:Dependents" group-by="wd:employee_client_id"> 
     <xsl:value-of select="wd:project_id"/> 
       <xsl:value-of select="$DELIMITER"/> 
     <xsl:value-of select="wd:plan_id"/> 
       <xsl:value-of select="$DELIMITER"/> 
     <xsl:value-of select="wd:employee_client_id"/> 
       <xsl:value-of select="$DELIMITER"/> 
     <xsl:value-of select="wd:employee_name"/> 
+0

非常感谢迈克尔,我想通了这一点,但没有张贴和回答。我真的很感谢你的帮助。 –