2013-03-26 59 views
1

您好我有下面的XML选择在XSLT

<primaryie> 
    <content-style font-style="bold">VIRRGIN system 7.204, 7.205</content-style> 
    </primaryie> 

,并通过应用下面的XSLT我能够选择号码。

<xsl:value-of select="current()/text()"/> 

但在以下情况下

<primaryie> 
    <content-style font-style="bold">VIRRGIN system</content-style> 
    7.204, 7.205 
    </primaryie> 

如何做的是选择的号码?我想要使​​用xslt:内容样式的父项。

我也有一些情况下,两个xmls走到一起。如果两种情况都存在,请让我知道如何选择号码。下面

感谢

回答

1

使用

<xsl:template match="primaryie/text()"> 
    <!-- Processing of the two numbers here --> 
</xsl:template> 

可以肯定的模板将执行选择,你可以有一个xsl:apply-templates是选择想要的文本节点,这本身就是在选择要执行的模板。

例如

<xsl:template match="primaryi"> 
    <!-- Any necessary processing, including this: --> 
    <xsl:apply-templates select="text()"/> 
</xsl:template> 
+0

感谢@Dimitre这已经解决我的问题 – 2013-03-26 14:58:59

+0

@MarsoniNm,欢迎您。 – 2013-03-26 15:43:37

0

我认为使用一个类似模板的设计应该有所帮助:

<xsl:template match="primaryie"> 
    <!-- Do some stuffs here, if needed --> 
    <!-- With the node() function you catch elements and text nodes (* just catch elements) --> 
    <xsl:apply-templates select="node()"/> 
</xsl:template> 

<xsl:template match="content-style"> 
    <!-- Do some stuffs here, if needed --> 
    <!-- same way --> 
    <xsl:apply-templates select="node()"/> 
</xsl:template> 

<!-- Here you got the template which handle the text nodes. It's probably better to add the ancestor predicate to limit its usage to the only text nodes we need to analyze ('cause the xslt processor often has some silent calls to the embedded default template <xsl:template match="text()"/> and override it completely could have some spectacular collaterall damages). --> 
<xsl:template match="text()[ancestor::primaryie]"> 
    <!-- Do your strings 'cooking' here --> 
</xsl:template> 
1
<xsl:template match="content-style"> 
    <xsl:value-of select="parent::*/text()"/> 
</xsl:template> 

,或者

<xsl:template match="content-style"> 
    <xsl:value-of select="../text()"/> 
</xsl:template>