|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Help with recursion (was: my brain is hurting)
Hi,
Tempore 11:04:32, die 01/15/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Chris Picton <chrisp@xxxxxxxxxxxxx>: the 'useparent' attribute specifies if that user or group should inherit its settings from its parent (1), or if it should specify its own (0). I am trying to get a list of users per group who should use the settings defined by that group.I'm not quite sure what yis the purpose of this parameter. In the above case, user 'phil' is not inheriting setting from the parent, and as such wont appear in the list for any group. Starting from this XML: <?xml version="1.0" encoding="UTF-8"?> <root>
<settings>
<user name="chris">
<module useparent="1" >
...empty...
</module>
</user>
<user name="phil">
<module useparent="0" >
...module settings...
</module>
</user>
<group name="default">
<module useparent="0" >
...module settings...
</module>
</group>
<group name="othergroup">
<module useparent="1" >
...empty...
</module>
</group>
</settings> <users>
<user name="chris" parent="othergroup">
...
</user>
<user name="phil" parent="othergroup">
...
</user>
<group name="default" parent="">
...
</group>
<group name="othergroup" parent="default">
...
</group>
</users>
</root>,the following stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:key name="settingGroup" match="settings/group[.//@useparent='1']" use="@name"/> <xsl:key name="settingUser" match="settings/user[.//@useparent='1']" use="@name"/> <xsl:key name="userGroupByName" match="users/group" use="@name"/> <xsl:key name="userGroupByParent" match="users/group" use="@parent"/> <xsl:key name="userUserByParent" match="users/user" use="@parent"/> <xsl:template match="root"> <xsl:apply-templates select="settings/group" mode="settings"/> </xsl:template> <xsl:template match="group" mode="settings"> <h1>Group: <xsl:value-of select="@name"/></h1> <ul> <xsl:apply-templates select="key('userGroupByParent',@name)" mode="users"/> </ul> </xsl:template> <xsl:template match="group[.//@useparent='1']" mode="settings-silent"> <xsl:apply-templates select="key('userGroupByParent',@name)" mode="users"/> </xsl:template> <xsl:template match="group" mode="users"> <xsl:apply-templates select="key('userUserByParent',@name)" mode="users"/> <xsl:apply-templates select="key('settingGroup',@name)" mode="settings-silent"/> </xsl:template> <xsl:template match="user" mode="users">
<xsl:if test="count(key('settingUser',@name))=1">
<li><xsl:value-of select="@name"/></li>
</xsl:if>
</xsl:template></xsl:stylesheet> will produce this result: <h1>Group: default</h1> <ul> <li>chris</li> </ul> <h1>Group: othergroup</h1> <ul></ul> As far as I understood your question, this should be the output you're looking for.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








