2013-10-25 73 views
1

「xmlns =」VL01「似乎是導致樣式表失敗(如果移除的話可以正常工作),不知道如何解決樣式表。我覺得這是基本的XLST 101但我有一個很難包裝我的大腦周圍。任何幫助,將不勝感激。乾杯未定義命名空間的問題

XML

<?xml version="1.0" encoding="utf-8"?> 
<Report xsi:schemaLocation="VL01 http://site.com/ReportServer?%2FVMS%20Reports%2FVL01&amp;rs%3ACommand=Render&amp;rs%3AFormat=XML&amp;rs%3ASessionID=lk44ff55z5q3ck3b5pfuxo45&amp;rc%3ASchema=True"  Name="VL01"  textbox41="VL01 - Checklist Report&#xD;&#xA;"  textbox1946=" 2) Target Element&#xD;&#xA;     Target Element List&#xD;&#xA;        Windows 7&#xD;&#xA;3) Report Options&#xD;&#xA; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="VL01"> 

<list2> 
    <Item_Collection> 
     <Item /> 
    </Item_Collection> 
</list2> 
<list1> 
    <list1_Details_Group_Collection> 
     <list1_Details_Group 
      Key="V0001070" 
      EffectiveDate="04 Mar 1998 16:03:47:000" 
      LongName2="Name..."/> 
    </list1_Details_Group_Collection> 
</list1> 
</Report> 

XSL

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<xsl:output method="xml" version="4.0" indent="yes"/> 

<xsl:variable name="var-checklist_name"> 
    <xsl:value-of select="substring-after(substring-before(translate(Report/@textbox1946, '&#xD;&#xA;', ''),'3)'),'Target&#x00A0;Element&#x00A0;List')"/> 
</xsl:variable><xsl:template match="/"> 

<html> 
<body> 
    <table>  
     <xsl:apply-templates select="Report/list1/list1_Details_Group_Collection"/> 
    </table> 
</body> 
</html> 
</xsl:template> 

<xsl:template match="Report/list1/list1_Details_Group_Collection"> 
<xsl:for-each select="list1_Details_Group"> 
    <Import_List> 
     <Checklist_Name>  
      <xsl:value-of select="normalize-space(translate($var-checklist_name, '&#x00A0;', ' '))"/> 
     </Checklist_Name> 
     <Vuln_ID><xsl:value-of select="number(substring-after(@VulKey,'V'))"/></Vuln_ID> 
     <Short_Name><xsl:value-of select="substring(@LongName2,1,255)"/></Short_Name> 
     <Release_Date><xsl:value-of select="substring(@EffectiveDate,1,11)"/></Release_Date> 
    </Import_List> 
</xsl:for-each> 
</xsl:template> 

</xsl:stylesheet> 

回答

0

聲明命名空間中xsl:stylesheet前綴(任何前綴)。示例:

xmlns:vl="VL01" 

更新您的路徑以包含前綴。例如:

match="vl:Report/vl:list1/vl:list1_Details_Group_Collection" 

此更新版本會產生輸出。除了命名空間聲明和更新帶有前綴的所有路徑外,我還必須更改xsl:output中的版本。

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:vl="VL01"> 
    <xsl:output method="xml" version="1.0" indent="yes"/> 

    <xsl:variable name="var-checklist_name"> 
     <xsl:value-of select="substring-after(substring-before(translate(Report/@textbox1946, '&#xD;&#xA;', ''),'3)'),'Target&#x00A0;Element&#x00A0;List')"/> 
    </xsl:variable> 

    <xsl:template match="/"> 
     <html> 
      <body> 
       <table>  
        <xsl:apply-templates select="vl:Report/vl:list1/vl:list1_Details_Group_Collection"/> 
       </table> 
      </body> 
     </html> 
    </xsl:template> 

    <xsl:template match="vl:Report/vl:list1/vl:list1_Details_Group_Collection"> 
     <xsl:for-each select="vl:list1_Details_Group"> 
      <Import_List> 
       <Checklist_Name>  
        <xsl:value-of select="normalize-space(translate($var-checklist_name, '&#x00A0;', ' '))"/> 
       </Checklist_Name> 
       <Vuln_ID><xsl:value-of select="number(substring-after(@VulKey,'V'))"/></Vuln_ID> 
       <Short_Name><xsl:value-of select="substring(@LongName2,1,255)"/></Short_Name> 
       <Release_Date><xsl:value-of select="substring(@EffectiveDate,1,11)"/></Release_Date> 
      </Import_List> 
     </xsl:for-each> 
    </xsl:template> 

</xsl:stylesheet> 
+0

謝謝你的快速回復,仍然沒有工作 – SoBeK

+0

@SoBeK - 你更新所有的路徑?如果我有一分鐘,我會自己嘗試一下,看看是否還有其他問題。 –

+0

yes(thank you for the quick reply btw) Modified XSL

SoBeK