Subject: [xsl] Pass XML document (*not* file path!) as parameter to XSLT From: "david bessire" <david_bessire@xxxxxxxxxxx> Date: Thu, 17 May 2007 18:54:47 +0000 |
What's the proper way to pass an XML document as a parameter to an XSLT, without writing that document to a file and passing the filepath to the XSLT ?
In Java code, i create a org.dom4j.Document that describes a user's roles and permissions; the structure looks like:
<pre> <permsroles> <role>Contributor</role> <perm>View</perm> </permsroles> </pre>
These permissions are used to restrict menu items a user is allowed to access. The menu items are described by a static xml document which looks like:
<pre> <menuItems> <menuItem id="1" parentId="0"> <ItemURL>URL1</ItemURL> <permsroles> <role>ADMIN</role> <role>Contributor</role> </permsroles> </menuItem> <menuItem id="11" parentId="1"> <ItemURL>URL2</ItemURL> </menuItem> <menuItem id="2" parentId="0"> <ItemURL>URL3</ItemURL> <permsroles> <perm>View</perm> </permsroles> </menuItem> </menuItems> </pre>
i want to use an XSLT to remove restricted menu items from the static document by passing the <permsroles> document as a parameter to the XSLT. My transform looks like:
<pre> <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0">
<xsl:param name="permsroles"/> <xsl:variable name="permsrolesLookup" select="document($permsroles)"/>
<xsl:template match="/menuItems"> <menuItems> <xsl:for-each select="menuItem"> <xsl:choose >
<xsl:call-template name="resolve-hierarchical-permissions"> <xsl:with-param name="id"> <xsl:value-of select="@id"/> </xsl:with-param> </xsl:call-template> </xsl:when> </xsl:choose> </xsl:for-each> </menuItems> </xsl:template>
<xsl:template name="resolve-hierarchical-permissions" match="menuItem"> <xsl:param name="id"/> <xsl:choose>
<xsl:when test="not(permsroles) or permsroles/role/text() = $permsrolesLookup/permsroles/role/text() or permsroles/perm/text() = $permsrolesLookup/permsroles/perm/text()">
<menuItem> <xsl:attribute name="id"> <xsl:value-of select="@id"/> </xsl:attribute> <xsl:attribute name="parentId"> <xsl:value-of select="@parentId"/> </xsl:attribute>
<ItemURL> <xsl:value-of select="./ItemURL"/> </ItemURL> </menuItem>
<xsl:for-each select="/menuItems/menuItem[@parentId = $id]"> <xsl:call-template name="resolve-hierarchical-permissions"> <xsl:with-param name="id"> <xsl:value-of select="@id"/> </xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:when> </xsl:choose> </xsl:template>
</xsl:stylesheet> </pre>
Thanks, david bessire
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
AW: [xsl] XML Prague 2007 June 16th, Huditsch, Roman (LNG | Thread | RE: [xsl] Pass XML document (*not* , Michael Kay |
Re: [xsl] How do I change a XSL sty, kieters c | Date | [xsl] Opening XSL output in a new w, Vishnu Vardhan P |
Month |