在xslt中的选择

时间:2013-03-26 10:57:15

标签: xslt

嗨,我有以下xml

 <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聚在一起。如果两种情况都存在,请告诉我如何选择号码。

由于

3 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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>

答案 2 :(得分: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>