簡體   English   中英

如何在XSLT中合並兩個模板?

[英]How to combine two templates in XSLT?

我有兩個XSLT模板,需要將它們組合成一個模板,然后按字母順序對其進行排序:

<xsl:template match="properties-for-sale">
  <xsl:for-each select="entry">
    <option value="{name}">
        <xsl:value-of select="name"/>
    </option>
  </xsl:for-each>
</xsl:template>

<xsl:template match="properties-for-rent">
  <xsl:for-each select="entry">
    <option value="{name}">
        <xsl:value-of select="name"/>
    </option>
  </xsl:for-each>
</xsl:template>

如何在XSLT中實現?

謝謝你的幫助!

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

  <xsl:template match="properties-for-sale|properties-for-rent">
    <xsl:for-each select="entry">
      <xsl:sort select="name" order="ascending"/>
      <option value="{name}">
        <xsl:value-of select="name"/>
      </option>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

使用| 用於多個XPath ..並使用<xsl:sort>對值進行排序..

如果您想了解更多有關參考!

http://www.w3schools.com/xsl/el_sort.asp

您可以使用| 匹配運算符

<xsl:template match="properties-for-sale|properties-for-rent">
  <xsl:for-each select="entry">
    <option value="{name}">
        <xsl:value-of select="name"/>
    </option>
  </xsl:for-each>
</xsl:template>

暫無
暫無

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

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