簡體   English   中英

在xslt中選擇

[英]Selection in 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:parent的內容樣式。

我也有一些情況下,兩個XML在一起。 如果兩種情況都存在,請讓我知道如何選擇號碼。

謝謝

<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>

用途

<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>

我認為使用類似於以下模板的模板設計應該會有所幫助:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM