XPath Not Working

A seemingly simple XPath expression to modify some nodes in web.xml during maven build process using XMLTask from oops consultancy didn’t work. Article Little Back Corners nailed the issue — namespace declarations in xml file. I have used local-name() function to workaround the issue. Below is an example:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
   <display-name>Log4j configuration Servlet</display-name>


XSLT to output servlet-class node value of servlet log4j:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">

<xsl:value-of select="/*[local-name()='web-app']/*[local-name()='servlet']/*[local-name()='servlet-name' and text()='log4j']/../*[local-name()='servlet-class']"></xsl:value-of>



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s