Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPath WildCard Help

Status
Not open for further replies.

stsuing

Programmer
Aug 22, 2001
596
US
What is the XPath syntax to do the following

Here is the XML
<?xml version="1.0" encoding="utf-8" ?>
<clientAddressRanges xmlns=" <clientAddressRange start="192.128.133.0" end="192.128.133.255" />
<clientAddressRange start="192.128.134.0" end="192.128.134.255" />
</clientAddressRanges>

I want to find the node by the first 3 octets of ip. For example get me the node that has "192.128.134" in a start attribute.

Something like...
"clientAddressRanges/clientAddressRange[matches(@start,'" & "192.128.134"& "')]"

Any help is appreciated.
 
If no extension function is used, split can be awkward. For ip address specific struction, brut-force can be done like this.
[tt]
<xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:dfns="<xsl:template match="dfns:clientAddressRanges">
<xsl:for-each select="dfns:clientAddressRange/@start">
<xsl:variable name="ip" select="." />
<xsl:variable name="c1" select="substring-before($ip,'.')" />
<xsl:variable name="t1" select="substring-after($ip,'.')" />
<xsl:variable name="c2" select="substring-before($t1,'.')" />
<xsl:variable name="t2" select="substring-after($t1,'.')" />
<xsl:variable name="c3" select="substring-before($t2,'.')" />
<xsl:if test="concat($c1,'.',$c2,'.',$c3)='192.128.134'">
[blue]<xsl:comment>A match has been found---do something here.</xsl:comment>[/blue]
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top