Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <a>
- <b>zyx</b>
- <b>wvu</b>
- <b>tsr</b>
- <b>qpo</b>
- </a>
- a/b[.='tsr']
- a/b[.='tsr']/position()
- int position = doc.SelectNodes("a/b[.='tsr']/preceding-sibling::b").Count + 1;
- // Check the node actually exists
- if (position > 1 || doc.SelectSingleNode("a/b[.='tsr']") != null)
- {
- Console.WriteLine("Found at position = {0}", position);
- }
- count(a/b[.='tsr']/preceding-sibling::*)+1.
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method="xml" encoding="utf-8" indent="yes"
- omit-xml-declaration="yes"/>
- <xsl:template match="a/*[text()='tsr']">
- <xsl:number value-of="position()"/>
- </xsl:template>
- <xsl:template match="text()"/>
- </xsl:stylesheet>
- count(a/b[.='tsr']/preceding::a)+1.
- count(a/b[.='tsr']/preceding::*)+1.
- using System;
- using System.Xml;
- public class XpathFinder
- {
- public static void Main(string[] args)
- {
- XmlDocument xmldoc = new XmlDocument();
- xmldoc.Load(args[0]);
- foreach ( XmlNode xn in xmldoc.SelectNodes(args[1]) )
- {
- for (int i = 0; i < xn.ParentNode.ChildNodes.Count; i++)
- {
- if ( xn.ParentNode.ChildNodes[i].Equals( xn ) )
- {
- Console.Out.WriteLine( i );
- break;
- }
- }
- }
- }
- }
- count(a/b[.='tsr']/preceding-sibling::*)+number(boolean(a/b[.='tsr']))
- index-of(//b, //b[.='tsr'])
- count(attr/value[.='$TARGET']/preceding-sibling::*)+1
- count(attr/value[.='$TARGET']/preceding::*) + 1
Add Comment
Please, Sign In to add comment