Guest User

Untitled

a guest
Mar 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <a>
  2. <b>zyx</b>
  3. <b>wvu</b>
  4. <b>tsr</b>
  5. <b>qpo</b>
  6. </a>
  7.  
  8. a/b[.='tsr']
  9.  
  10. a/b[.='tsr']/position()
  11.  
  12. int position = doc.SelectNodes("a/b[.='tsr']/preceding-sibling::b").Count + 1;
  13.  
  14. // Check the node actually exists
  15. if (position > 1 || doc.SelectSingleNode("a/b[.='tsr']") != null)
  16. {
  17. Console.WriteLine("Found at position = {0}", position);
  18. }
  19.  
  20. count(a/b[.='tsr']/preceding-sibling::*)+1.
  21.  
  22. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  23. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  24. <xsl:output method="xml" encoding="utf-8" indent="yes"
  25. omit-xml-declaration="yes"/>
  26. <xsl:template match="a/*[text()='tsr']">
  27. <xsl:number value-of="position()"/>
  28. </xsl:template>
  29. <xsl:template match="text()"/>
  30. </xsl:stylesheet>
  31.  
  32. count(a/b[.='tsr']/preceding::a)+1.
  33.  
  34. count(a/b[.='tsr']/preceding::*)+1.
  35.  
  36. using System;
  37. using System.Xml;
  38.  
  39. public class XpathFinder
  40. {
  41. public static void Main(string[] args)
  42. {
  43. XmlDocument xmldoc = new XmlDocument();
  44. xmldoc.Load(args[0]);
  45. foreach ( XmlNode xn in xmldoc.SelectNodes(args[1]) )
  46. {
  47. for (int i = 0; i < xn.ParentNode.ChildNodes.Count; i++)
  48. {
  49. if ( xn.ParentNode.ChildNodes[i].Equals( xn ) )
  50. {
  51. Console.Out.WriteLine( i );
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. }
  58.  
  59. count(a/b[.='tsr']/preceding-sibling::*)+number(boolean(a/b[.='tsr']))
  60.  
  61. index-of(//b, //b[.='tsr'])
  62.  
  63. count(attr/value[.='$TARGET']/preceding-sibling::*)+1
  64.  
  65. count(attr/value[.='$TARGET']/preceding::*) + 1
Add Comment
Please, Sign In to add comment