Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nokogiri (Ruby) and XPath

Does Nokogiri only support XPath 1.0? I'm trying to do simple string replacement in a value-of cell, like so (where element contains something like '* My string (useless text)')

<xsl:value-of select="replace(element,'^\*\ (.+)\ \(.*\)$','\\1')">

Is this poorly formed XSL? Or is there a limitation with Nokogiri?

like image 398
JP. Avatar asked May 14 '10 23:05

JP.


People also ask

What is Nokogiri Ruby?

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby. It provides a sensible, easy-to-understand API for reading, writing, modifying, and querying documents. It is fast and standards-compliant by relying on native parsers like libxml2 (CRuby) and xerces (JRuby).

How does Nokogiri work?

Nokogiri makes an attempt to determine whether a CSS or XPath selector is being passed in. It's possible to create a selector that fools at or search so occasionally it will misunderstand, which is why we have the more specific versions of the methods.

What is GEM Nokogiri?

The Nokogiri gem is an incredible open-source tool that parses HTML and XML data. It is one of the most widely used gems available, and it can really take your Ruby app to another level for data with its ability to help you intuitively scrape websites.

What is Nokogiri used for in rails?

Nokogiri is an open source library in Ruby used to read HTML and XML Basically it is used to read information from websites to use for your application.


1 Answers

The replace() function is only defined in XPath 2.0 (and XPath 2.x is only supported by XSLT 2.x, not XSLT 1.0)

Nokogiri uses libxml2, which only supports XPath 1.0/XSLT1.0

like image 183
Dimitre Novatchev Avatar answered Dec 05 '22 22:12

Dimitre Novatchev