Forum Moderators: open
<xsl:value-of select="general/alert[id='12053']/desc"/>
It returns in the outputted file:
"10.10.10.24 resolves as hostname.domainname.com.<br/>"
I really only want:
"10.10.10.24 resolves as hostname.domainname.com."
Or even "hostname.domainname.com"
Any way to parse/select only that portion? hostname.domainname.com is a variable, obviously, and is different for each IP/host.
If you are using PHP to execute your XSL, then you are stuck XSLT/XPath 1.0, which means that you need to use kind of a pathetic lash-up, like so:
XML:
<desc>10.10.10.24 resolves as hostname.example.com.[red][b]<br/>[/b][/red]</desc> Note that I escaped the "<br/>". This is because proper XML will interpret this as a tag, and it will not be included in the string, so yours must be declared that way.
This XSLT works:
XSLT:
<xsl:variable name="spaz" select="general/alert[@id='12053']/desc"/> <xsl:value-of select="substring-before(substring-after($spaz,'as '), '.<br')"/>
I'm working with reports generated by Nessus, a vulnerability scanner. It creates the XML, so I have no control over that (to escape, as you suggested).
They do provide XSL sheets, and via their client software, creates HTML output with the XSL/XML. So, all I have control over, is the XSL. I'm not sure if their client uses PHP or...?
I'll tinker with the feedback you gave, and hopefully can get something workable. I may post a follow up question here, but if there's a good template/example site that includes more info/examples on the substring technique, I'm happy to reference that as well if anyone can provide a link. I spent a lot of time googling for value-of tips/tricks but came up empty. Thanks much.
<desc>10.10.10.24 resolves as hostname.example.com.[red][b]<br/>[/b][/red]</desc> Then you should not be getting the
<br/> included in your string. Like I said, if they accept XSLT 2, then you have a lot more to work with. XPath 2 allows RegEx.
I had to break the XPath into two for my example, because libxslt [xmlsoft.org] (the XSLT 1 processor used by PHP) wouldn't do a proper substring parse of the direct node.
I tried doing this:
<xsl:value-of select="substring-before(substring-after([red][b].[/b][/red],'as '), '.<br')"/> but it didn't work. I needed to put it in a "variable" first.
Hope it works out for you.
Thanks -- you solved it!
Here's what worked:
<xsl:variable name="spaz" select="general/alert[id='12053']/desc"/>
<xsl:value-of select="substring-before(substring-after($spaz,'as '), '.<br')"/>
(I removed the @ before "id=" in the first line. Prior to that, no results. After that -- beautiful.
No other changes needed. Output: perfect.
I'm planning on submitting these modified templates (which are improved over the originals) back to TenableSecurity.com / nessus.org, and will include a thanks to you in there for getting me past the last hurdle. I'm hoping they'll distribute them with the windows package.