2

I've got a XML-document with this content:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="/Stylesheet.xsl" ?>

How can I find out using ANT's <xmltask> whether the <?xml-stylesheet ?> node already exists?

Hedge
  • 16,142
  • 42
  • 141
  • 246

1 Answers1

1

That's a special node type called processing instruction. You can query it using XPath to find out if it exists and what its attributes are:

/processing-instruction('xml-stylesheet')
Peter Walser
  • 15,208
  • 4
  • 51
  • 78
  • 1
    That works flawlessly. How can I get the type or href-attribute? – Hedge Aug 22 '13 at 15:47
  • 1
    That's tricky, because processing instructions have pseudo-attributes, which cannot be directly accessed. You can however extract the content as string, and use the XPATH sting functions to get the href value: substring-before(substring-after( string(/processing-instruction('xml-stylesheet')),'href="'), '"') – Peter Walser Aug 22 '13 at 16:31