gharmon77 Posted February 3, 2011 Share Posted February 3, 2011 A small portion of the xml file I'm working with is at the end. Currently, when parsing the data for email, I'm extracting using the following in my xsl: <xsl:if test="contains(text(), 'ERROR at line ') or (contains(text(), 'ORA-')) and not(contains(text(), 'PL/SQL'))"> <xsl:value-of select="." /> <br /></xsl:if> Instead of using this If/And/Or approach, is there a better way to return the "ERROR" line and the following 2 lines? (btw, I've excluded the section of the xml that contains the PL/SQL data in my sample xml at the end) ERROR at line 1:ORA-01403: no data foundORA-06512: at line 574 Something like: <xsl:value-of select=".[position() <=3]" /> So that it returns the next 3 elements from the current element?My sample XML file <?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="C:\test\gh.xsl"?><deployment project="REL"> <parameters> <parameter name="$LastIntegrationStatus" value="Success" /> </parameters> <build><buildresults project="RELTest"> <message level="Info"><![CDATA[Buildfile: file:///c:/SVN/Misc Utilities/REL/db.build]]></message> <message level="Info"><![CDATA[Target framework: Microsoft .NET Framework 2.0]]></message> <message level="Info"><![CDATA[Target(s) specified: sendmail_logout]]></message> <task name="loadtasks"> <message level="Info"><![CDATA[Scanning assembly "Net.Sf.Dbdeploy" for extensions.]]></message> <duration>0</duration> </task> <task name="loadtasks"> <message level="Info"><![CDATA[Scanning assembly "Com.ThoughtWorks.SecurityFunctions" for extensions.]]></message> <duration>15.6248</duration> </task> <task name="loadtasks"> <message level="Info"><![CDATA[Scanning assembly "NAnt.Contrib.Tasks" for extensions.]]></message> <duration>46.8744</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="include"> <task name="tstamp"> <message level="Info"><![CDATA[Thursday]]></message> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <duration>31.2496</duration> </task> <task name="include"> <duration>0</duration> </task> <task name="tstamp"> <message level="Info"><![CDATA[Thursday]]></message> <duration>0</duration> </task> <task name="property"> <duration>0</duration> </task> <target name="sendmail_logout"> <task name="mail"> <message level="Info"><![CDATA[Sending mail to team@fake.com]]></message> <duration>1484.356</duration> </task> <duration>1499.9808</duration> </target> <duration>1624.9792</duration></buildresults> <buildresults project="RELTest"> <target name="apply_deltas"> <task name="property"> <duration>0</duration> </task> <task name="call"> <target name="sqlplus"> <task name="exec"> <message level="Info"><![CDATA[Compiling : SR08330]]></message> <message level="Info"><![CDATA[Compiling : SR08343]]>></message> <message level="Info"><![CDATA[Compiling : SR09117]]></message> <message level="Info"><![CDATA[Compiling : SR09238.01]]></message> <message level="Info"><![CDATA[Compiling : SR09238.02]]></message> <message level="Info"><![CDATA[Compiling : SR09243.01]]></message> <message level="Info"><![CDATA[Compiling : SR09309.01]]></message> <message level="Info"><![CDATA[Compiling : SR09309.02]]></message> <message level="Info"><![CDATA[Compiling : SR09309.03]]></message> <message level="Info"><![CDATA[Compiling : SR10006.01]]></message> <message level="Info"><![CDATA[Compiling : SR10006.02]]></message> <message level="Info"><![CDATA[Compiling : SR10006.03]]></message> <message level="Info"><![CDATA[Compiling : SR10006.04]]></message> <message level="Info"><![CDATA[Compiling : SR10006.05]]></message> <message level="Info"><![CDATA[Compiling : SR10006.06]]></message> <message level="Info"><![CDATA[Compiling : SR10006.07]]></message> <message level="Info"><![CDATA[Compiling : SR10067.01]]></message> <message level="Info"><![CDATA[Compiling : SR10067.02]]></message> <message level="Info"><![CDATA[Compiling : SR10067.03]]></message> <message level="Info"><![CDATA[Compiling : SR10083.05]]></message> <message level="Info"><![CDATA[Compiling : SR10125.02]]></message> <message level="Info"><![CDATA[Compiling : SR10146]]></message> <message level="Info"><![CDATA[Compiling : SR10161.01]]></message> <message level="Info"><![CDATA[Compiling : SR10161.03]]></message> <message level="Info"><![CDATA[ERROR at line 1:]]></message> <message level="Info"><![CDATA[ORA-01403: no data found]]></message> <message level="Info"><![CDATA[ORA-06512: at line 574]]></message> <duration>1590495.2664</duration> </task> <duration>1590510.8912000002</duration> </target> <duration>1590510.8912000002</duration> </task> <duration>1590510.8912000002</duration> </target></build></deployment> Link to comment Share on other sites More sharing options...
Martin Honnen Posted February 4, 2011 Share Posted February 4, 2011 Well first of all with XSLT 1.0 stylesheets when you use <xsl:value-of select="foo"/> and "foo" selects a node-set with more than one node then only the value of the first node in the node-set is output.With XSLT 2.0 you might want <xsl:value-of select=". | following-sibling::message[position() < 3]"/> with XSLT 1.0 you need to use a for-each select=". | following-sibling::message[position() < 3]". Link to comment Share on other sites More sharing options...
gharmon77 Posted February 4, 2011 Author Share Posted February 4, 2011 Ya, the "if" statements I have are inside a <span> for linking which is inside the for-each statement .. And ya, using 1.0. Will try out 2.0 lingo, see what happens. Thanks. Link to comment Share on other sites More sharing options...
Martin Honnen Posted February 4, 2011 Share Posted February 4, 2011 Note that using version="2.0" successfully requires using an XSLT 2.0 processor like Saxon 9 or like AltovaXML Tools or like XQSharp. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.