2014-04-09 20 views
3

我有這個片段的XSLT代碼:如何從串聯變量清理噪音字符XSLT

<xsl:variable name="VulnerabilityURI"> 
    http://web.nvd.nist.gov/view/vuln/detail?vulnId= 
</xsl:variable> 
<xsl:variable name="WeaknessURI"> 
    http://cwe.mitre.org/data/definitionsn 
</xsl:variable> 
<xsl:variable name="CVEURI"> 
    http://www.cve.mitre.org/cgi-bin/cvename.cgi?name= 
</xsl:variable> 
<xsl:variable name="cweID" select="substring(vuln:cwe/@id,5)" /> 
<xsl:template match="/*/*"> 
    <xsl:variable name="cveID" select="vuln:cve-id" /> 
    <xsl:element name="rdf:Description"> 
     <xsl:attribute name="rdf:about"> 
      <xsl:value-of select="concat($VulnerabilityURI, $cveID)" /> 
     </xsl:attribute> 
     <aseg:cveID> 
      <xsl:value-of select="concat($CVEURI,$cveID)" /> 
     </aseg:cveID> 

和輸出來像下面這樣:

<?xml version="1.0" encoding="UTF-8"?> 
    ..... 
    ..... 
    <rdf:Description rdf:about="&#10;&#9;&#9;http://web.nvd.nist.gov/view/vuln/detail  
    vulnId=&#10;&#9;CVE-2010-2227"> 
    <aseg:cveID> 
    http://www.cve.mitre.org/cgi-bin/cvename.cgi?name= 
CVE-2010-2227</aseg:cveID> 

正如你可以在此看到結果的一部分,我想要的連接變量產生未知字符

&#10;&#9 

任何人都可以幫助我無花果排除這個問題?!!

回答

5

這些「噪音字符」是換行符和製表符。取而代之的

<xsl:variable name="VulnerabilityURI"> 
    http://web.nvd.nist.gov/view/vuln/detail?vulnId= 
</xsl:variable> 

你可以寫

<xsl:variable 
    name="VulnerabilityURI" 
    select="'http://web.nvd.nist.gov/view/vuln/detail?vulnId='" > 

,然後你不會得到這些字符。

您還需要在設置CVE ID的地方進行類似的操作。

+0

不要忘記將選擇的字符串換成引號('),例如:'select =''http://web.nvd.nist.gov/view/vuln/detail?vulnId='「'。 +1 –

+0

太棒了!非常感謝你 – Tech

+0

謝謝@DanielHaley,我現在編輯它。 –