开发者

XSL beginner question

开发者 https://www.devze.com 2023-01-13 12:44 出处:网络
I want to understand, in general, what this means: <xsl:template match=\"foo:barLists[@mode = \'Dummy Filter\']\"

I want to understand, in general, what this means:

<xsl:template match="foo:barLists[@mode = 'Dummy Filter']" 
              mode="d开发者_StackOverflow社区ummy-filter-cache" priority="2">

I'm looking for some insight to what this does so I may learn a bit about XSL


 <xsl:template 

This element defines a template. We'll give it data later with an apply-template element

 match="foo:barLists[@mode = 'Dummy Filter']" 

This template uses the element barLists in the namespace foo which has an attribute of mode which is set to "Dummy Filter". i.e. <foo:barList mode="Dummy Filter"> .... </foo:barList>

 mode="dummy-filter-cache" 

This tempalte has a mode of "dummy-filter-cache". I have no idea what that means. w3schools.com only says about mode: "Optional. Specifies a mode for this template"

priority="2">

This tempate has a priority of 2. If there's another template which also matches that element with a priority of 1, that one wins.


In general, you are matching specific nodes with specific attributes in an XML file.

I suggest you look at a tutorial on XSL.


mode attribute of xsl:template allows you to create several templates that have same match attribute. With mode you can choose which one of these templates gets applied in different cases. This might be useful if you need to apply the same content several times with different formatting at some of these times.

A template with a mode will be instantiated only when you have set the same mode on an xsl:apply-templates element whose select attribute matches the match attribute on the xsl:template element.

Let's suppose you have templates

  1. <xsl:template match="foo">
    and
  2. <xsl:template match="foo" mode="bar">

Then <xsl:apply-templates select="foo" mode="bar"/> will match the template #2 while
<xsl:apply-templates select="foo"/> and <xsl:apply-templates/> will match the template #1.

0

精彩评论

暂无评论...
验证码 换一张
取 消