This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
displaying only certain parts of an xml doc using xsl
- From: "Denis McCarthy" <dmccarthy at omnipaygroup dot com>
- To: <XSL-List at lists dot mulberrytech dot com>
- Date: Mon, 15 Apr 2002 13:02:52 +0100
- Subject: [xsl] displaying only certain parts of an xml doc using xsl
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi there,
I'm trying to use server-side xsl in my jsp appliction for the first time
(using Xalan). I have an xml document (contact_details.xml) whch contains
several <institution> elements. I want to decide which institution element
to use dynamically on the jsp page by passing in a parameter to the xsl
document. However I am having trouble getting the xsl to process the element
I want. Here is the general layout of the xml file:
<?xml version="1.0"?>
<institutionList>
<institution>
<instId>00000002</instId>
<pageHeading>blah blah</pageHeading>
.
.
</institution>
<institution>
<instId>00000004</instId>
.
.
</institution>
</institutionList>
In my xsl file, I want to only process the <institution> element whose
<instId> value is the same as a parameter that I pass in.
So at the moment, I am trying (in my xsl file)
.
.
<xsl:param name="instId" select="'default'"/>
<xsl:template match="/">
<xsl:apply-templates
select="institutionList/institution[contains(instId,$instId)]"/>
</xsl:template>
followed by other generic formatting templates.
In the jsp page I have
<%
String paramValue = "00000002";
String xmlFile = "http://dmccarthy/contact_details.xml";
String xslFile =
"http://dmccarthy/ram/ramstatic/xsl/contactDetailsToHTML.xsl";
TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer =
tFactory.newTransformer(new StreamSource(xslFile));
transformer.setParameter("instId", paramValue);
transformer.transform(
new StreamSource(xmlFile), new StreamResult(out));
%>
I would think that this code should result in the displaying of the xml
<institution> element that has '00000002' as its <instId> value, but all I
get is a blank page. Could someone tell me where I'm going wrong?
Thanks very much
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list