2017-06-20 96 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

非常感謝邁克爾,我想通了這一點,但沒有張貼和回答。我真的很感謝你的幫助。 –