English 中文(简体)
XSLT 1.0 正常表达
原标题:XSLT 1.0 Regular Expression in for loop
  • 时间:2011-09-30 05:12:04
  •  标签:
  • regex
  • xslt

因此,我有Xml。

<depot id="D7">
    <address> 
        <number>6000</number> 
        <street>Yonge</street> 
        <city>Toronto</city> 
        <province>ON</province> 
        <postal_code>M2M 2E4</postal_code> 
    </address> 
</depot> 

我拥有数百座锡尔的仓库。

now in my xsl, I have defined a variable called locale that stores a postal code like "M1C". After this I want to select only those depot where the postal_code is like locale . In other words, If I specify locale to be "M1C", then I should get all the depot whose postal_code contains "M1C", so depot with "M1C A18", "M1C B2C", etc all should be in the result.

目前,我行文如下:

< xsl:for-each select="depot[address[postal_code=$locale]]">

这只给我贴上准确的邮政编码,而不是“M1C A18”、“M1C B2C”等。 我想用的是这样的东西。

<xsl:for-each select="depot[address[postal_code=*$locale*]]">

与野心相联,但并不奏效。 建议

问题回答

<>Use:

depot[starts-with(address/postal_code, $locale)]

这里我们假设,任何<代码><>depot 都有一个单一的<代码>address/postal_code descendent,而$ locale的任何可能价值都不是$ locale的其他任何可能价值的先决条件。

If, for example, the second assumption isn t true, then use:

depot[starts-with(address/postal_code, concat($locale,    ))]

在XPath 2.0(例如matches(<>/code>)功能)中,可提供真正的定期表达能力,但对于一个简单的问题而言,这种能力是必要的。

使用:

<xsl:for-each select="depot[contains(address/postal_code,$locale)]" />

仅与<代码>depot中包含下定义的碎块的内容相匹配。





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...