Subject: RE: [xsl] apply-templates with-param failed From: Xiaocun Xu <xiaocunxu@xxxxxxxxx> Date: Tue, 27 Sep 2005 06:48:09 -0700 (PDT) |
The source document is an output of a static code analyzer called FindBugs, following is a sample: <?xml version="1.0" encoding="UTF-8"?> <BugCollection version="0.9.3" sequence="0" timestamp="1127452941384" release=""> <Project filename="<<unnamed project>>"> <SrcDir>X:\MyServer\classfiles</SrcDir> </Project> <BugInstance type="DE_MIGHT_IGNORE" priority="2" abbrev="DE" category="CORRECTNESS" uid="258"> <ShortMessage>Method might ignore exception</ShortMessage> <LongMessage>DE: jsp_servlet._en.__notification_alert._jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) might ignore java.lang.Exception</LongMessage> <Class classname="jsp_servlet._en.__notification_alert"> <Message>In class jsp_servlet._en.__notification_alert</Message> </Class> <Method classname="jsp_servlet._en.__notification_alert" name="_jspService" signature="(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V" isStatic="false"> <SourceLine classname="jsp_servlet._en.__notification_alert" start="619" end="829" startBytecode="0" endBytecode="1284" opcodes="" sourcefile="__notification_alert.java"/> <Message>In method jsp_servlet._en.__notification_alert._jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)</Message> </Method> <SourceLine classname="" start="147" end="147" startBytecode="399" endBytecode="399" opcodes="25,25,25,182,167|58|44,25,18,178,184" sourcefile="../../com/avinamart/WebInterface/public_html/en/include/notification_head.inc"> <Message>At __notification_alert.java:[line 687]</Message> </SourceLine> <Class classname="java.lang.Exception" role="CLASS_EXCEPTION"> <Message>Exception class java.lang.Exception</Message> </Class> </BugInstance> <BugCategory category="PERFORMANCE"> <Description>Performance</Description> </BugCategory> <BugCategory category="CORRECTNESS"> <Description>Correctness</Description> </BugCategory> <BugCategory category="STYLE"> <Description>Style</Description> </BugCategory> <BugPattern type="DE_MIGHT_IGNORE" abbrev="DE" category="CORRECTNESS"> <ShortDescription>Method might ignore exception</ShortDescription> <Details><![CDATA[ <p> This method might ignore an exception. In general, exceptions should be handled or reported in some way, or they should be thrown out of the method.</p> ]]></Details> </BugPattern> <BugCode abbrev="DE"> <Description>Dropped or ignored exception</Description> </BugCode> <Errors></Errors> <FindBugsSummary></FindBugsSummary> <ClassFeatures></ClassFeatures> <History></History> </BugCollection> Yesterday, with you and help of the list, I was able to get the following XSLT work, without the document() and with-param: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <xsl:call-template name="splitByFunctionalAreas"/> </xsl:template> <xsl:template name="splitByFunctionalAreas"> <xsl:result-document href="messaging_bugs.xml"> <xsl:apply-templates select="BugCollection"/> </xsl:result-document> </xsl:template> <xsl:template match="BugCollection"> <!-- element BugCollection has to start on a new line; otherwise, FindBugs won't load successfully --> <xsl:text>	
</xsl:text> <xsl:element name="BugCollection"> <xsl:copy-of select="@*"/> <xsl:text>	
</xsl:text> <xsl:copy-of select="Project"/> <xsl:apply-templates select="BugInstance"/> <xsl:copy-of select="BugCategory"/> <xsl:copy-of select="BugPattern"/> <xsl:copy-of select="BugCode"/> <!-- following 3 elements are empty in source XML, copy anyway --> <xsl:copy-of select="Errors"/> <xsl:copy-of select="ClassFeatures"/> <xsl:copy-of select="History"/> </xsl:element> </xsl:template> <xsl:template match="BugInstance"> <xsl:variable name="vClassName" select="Class[1]/@classname"/> <xsl:if test="contains($vClassName, 'notification') or contains($vClassName, 'message')"> <xsl:copy-of select="."/> </xsl:if> </xsl:template> </xsl:stylesheet> Now I am just trying to extend it to read config from FunctionalAreaDef.xml and pass on the params, I encountered apply-templates with-param failed. Any suggestion would be appreciated, thanks. Xiaocun --- Michael Kay <mike@xxxxxxxxxxxx> wrote: > You haven't shown us the source document. Perhaps > its outermost element > isn't called BugCollection, or perhaps it's in a > namespace. > > Michael Kay > http://www.saxonica.com/ > > > -----Original Message----- > > From: Xiaocun Xu [mailto:xiaocunxu@xxxxxxxxx] > > Sent: 27 September 2005 02:08 > > To: xsl-list > > Subject: [xsl] apply-templates with-param failed > > > > Hi, > > > > I am working on splitting a FindBugs result XML > into > > multiple XMLs by finding keywords in > Class/@classname. > > Keywords for all functional areas are defined in > > FunctionalAreaDef.xml: > > <Application> > > <FunctionalArea name="message"> > > <Keywords> > > <Keyword>notification</Keyword> > > <Keyword>message</Keyword> > > </Keywords> > > </FunctionalArea> ... > > </Application> > > > > I use the following XSL to read > FunctionalAreaDef.xml, > > loop through each FunctionalArea element, create > an > > output file using the FunctioalArea/@name and pass > > Keywords to BugCollection element(in the source > > FindBugs XML): > > <xsl:variable name="vFunctionalArea" > > select="document('FunctionalAreaDef.xml')"/> > > <xsl:template match="/"> > > <xsl:for-each > > > select="$vFunctionalArea/Application/FunctionalArea"> > > <xsl:call-template > name="splitByFunctionalAreas"> > > <xsl:with-param name="pFunctionalAreaDef" > > select="."/> > > </xsl:call-template> > > </xsl:for-each> > > </xsl:template> > > <xsl:template name="splitByFunctionalAreas"> > > <xsl:param name="pFunctionalAreaDef" select="."/> > > <xsl:variable name="vFileName" > > select="$pFunctionalAreaDef/@name"/> > > <xsl:result-document > href="{$vFileName}_bugs.xml"> > > <xsl:apply-templates select="BugCollection"> > > <xsl:with-param name="pKeywords" > > select="$pFunctionalAreaDef/Keywords"/> > > </xsl:apply-templates> > > </xsl:result-document> > > </xsl:template> > > <xsl:template match="BugCollection"> > > <xsl:param name="pKeywords" select="."/> > > <xsl:value-of select="$pKeywords"/> > > ... > > > > Somehow the BugCollection template did not get > evoked > > as <xsl:value-of select="$pKeywords"/> seems not > > evaluated (the output file is empty with just a > XML > > header). I used matching mode as well, still no > luck. > > Any suggestion on what have I done wrong would be > > much appreciated. > > > > thanks, > > Xiaocun > > > > > > > > __________________________________ > > Yahoo! Mail - PC Magazine Editors' Choice 2005 > > http://mail.yahoo.com > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] apply-templates with-para, Michael Kay | Thread | [xsl] "Convert" true/false to 0/1, Aron Bock |
RE: [xsl] Question about XSLT IP pr, Michael Kay | Date | Re: [xsl] RELAX NG validator, Hank Ratzesberger |
Month |