xpath string as parameter from java
Natascia De Bortoli <[email protected]>
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <[email protected]> |
Hello at all!!
I need a method to pass a string as an XPATH query to a xsl file.
The String XPstr represent an XPATH query that selects some xml node and it must be passed to xsl by a *JAVA* application.
I've used node-set() common function but I've encountered some problems: it isn't seen as a "query string" and
no node(s) are selected by the selection!
Java code (used as example: the string XPstr passed as parameter depends on some user's settings and change each time):
public static void main(String[] args) throws Exception {
....
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource("theXSLFile"));
StreamSource xmlsource = new StreamSource("theXMLFile");
StreamResult output = new StreamResult(System.out);
*transformer.setParameter("XPstr","/HostGroupInfo//Process[@ProcStatus='OFF']");*
transformer.transform(xmlsource, output);
}
*The xsl code:
*
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:import href="templates.xsl"/>
*<xsl:variable name="XPstr"/>*
<xsl:template match="/">
<br>_________________________________________________________________________</br>
<xsl:for-each select="*exsl:node-set($XPstr)*">
<xsl:apply-templates select="ancestor-or-self::*"/>
<br>_________________________________________________________________________</br>
</xsl:for-each>
</xsl:template>
<xsl:template match="*">
<xsl:apply-imports/>
</xsl:template>
</xsl:stylesheet>
The XMl File (fragment):
<HostGroupInfo Group="LNL-2">
<HostData Status="1">
<HostName>lnl</HostName>
<UpTime>2848422</UpTime>
<Roles>
<Role Status="1">
<RoleName>wr-node</RoleName>
<Processes>
<Process Active="1" ProcStatus="OFF">
<ProcName>ntpd</ProcName>
<NumberOfIstances>1</NumberOfIstances>
</Process>
<Process Active="1" ProcStatus="S">
<ProcName>sbatchd</ProcName>
<NumberOfIstances>1</NumberOfIstances>
</Process>
....
</Processes>
</Role>
</Roles>
</HostData>
<HostData Status="1">
<HostName>msf</HostName>
<UpTime>78941</UpTime>
<Roles>
<Role Status="1">
<RoleName>wnode</RoleName>
<Processes>
<Process Active="1" ProcStatus="S">
...
</Process>
</Processes>
</Role>
</Roles>
</HostData>
</HostGroupInfo>
Could anyone help me, please?
Thank you very much.
Nat
_______________________________________________
exslt mailing list
[email protected]
http://www.exslt.org/list