2012-11-08 20 views
0

我與XPath表達式測試=「$角色/角色/角色=‘HOBSCS1GB’」的問題。任何人都可以幫忙解決。由於檢索XML變量在XSL文件,說是如果發現

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> 

    <xsl:template match="/"> 

    <xsl:variable name="roles"> 
    <roles> 
    <role>HOBSCS1ROI</role> 
    <role>HOBSCS1GB</role> 
    <role>HOBSCS1FT</role> 
    </roles> 
    </xsl:variable> 

    <xsl:if test="$roles/roles/role='HOBSCS1GB'"> 
     <xsl:value-of select="'YES'"/> 
    </xsl:if> 

    </xsl:template> 
</xsl:stylesheet> 
+0

如果您遇到問題,最好說出問題所在。 –

回答

2

假設你想找到如果該roles元素與文本=「HOBSCS1GB」一個或多個角色的元素:(撒克遜工程)

<xsl:if test="$roles/roles[role='HOBSCS1GB']"> 
    <xsl:value-of select="'YES'"/> 
</xsl:if> 

注意,某些解析器像微軟可能要求您使用node-set(),像這樣告訴解析器$roles是一個結果樹片段:(工程在msxsl)

​​

還是在xsltpro c:

<xsl:stylesheet ... xmlns:exsl="http://exslt.org/common" ... /> 

<xsl:if test="exsl:node-set($roles)/roles[role='HOBSCS1GB']"> 
    <xsl:value-of select="'YES'"/> 
</xsl:if> 
+0

非常好。我需要通過Tomcat進行這種轉換,但你的回答很清楚地解釋了它。非常感激 – topcat3