XSLT



5 Aug 10

I will be sharing future Snippets for use in Microsoft Visual Studio on my public dropbox here: http://db.tt/3p5Sav

At the time of writing only one is out there – it is “Surround in CDATA”. You may also read about that particular one here: Article on Stack Overflow: Can I define custom “surround with” templates in Visual Studio 2008?


Filed under: Code, Snippets, XSLT

Trackback Uri






8 Jun 10

In my daily work as frontend developer at www.bleau.dk I do a lot of XSLT “programming” – XPath is one of the things you need to master most. With the focus mainly set on closing tasks I have not had the time to test a – well nice to know thing with the “//” XPath operator. Tonight I finally found out what had been a question in my mind for at long period:

The “//” (decendant-or-self) XPath operator: Can it be used relative inside a full XPath? Will it “search” from the Document top, or start where it is placed inside the XPath selector?

An example XML:

<?xml version="1.0" encoding="utf-8"?>
<people>
  <group type="frontEnd">
    <person name="Sten" />
  </group>
  <group type="backend">
    <person name="Sten" />
  </group>
</people>

The two XPaths

//person[@name='Sten'] – Returns a nodeset containing 2 elements

//group[@type="frontEnd"]//person[@name='Sten'] – Returns a nodeset containing only 1 element

So as you can see the first one looked from the root (/People) and anywhere inside the document. The second one had the “//” inside a XPath, which in made the “//” operator look from the spot it was and below.

Conclusion

Well, I just got a litle wiser as I learned that I actually can use the “//” operator inside XPath selectors.

Links

Filed under: XSLT

Trackback Uri