Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Using RegExp in XSLT

  •  01-11-2007, 7:04 AM

    Using RegExp in XSLT

    Hello all,

    Im using XSLT to grab data from an XHTML page, part of the data I wish to grab is a Postcode, this is the XSLT statement I have to grab the postcode:

           <xsl:for-each select=".//h:a[starts-with(@href, 'http://local.google.com')]">

               <xsl:variable name="postcode" select="@href"/>
               <myns:hasPostcode><xsl:value-of select="$postcode" /></myns:hasPostcode>

           </xsl:for-each>

    The result of which I store in a variable $postcode. The variable will always be in this format:

    http://local.google.com/maps?f=q&amp;hl=en&amp;q=BN1%203HH&amp;ie=UTF8&amp;z=17&amp;om=1&amp;iwloc=A

    I wish to use a RegExp in the XSLT to grab the postcode (in bold). The postcodes are all in similar Google URL's format q=BN1%203HH&amp;     q=BN3%206QB&amp; 

    Is it possible to grab the text after the "q=" (in example BN1) but after the % character only grab the first 3 characters, as the second part of a UK postcode can only be three characters.

    I really appreciate any advice, I have tried some RegExp but just cant get them to work.

    Thanks.

     

     

View Complete Thread