Subject: [xsl] website transformation From: Saverio Perugini <sperugin@xxxxxxxxxxxxxxxx> Date: Wed, 15 Oct 2003 23:44:30 -0400 (EDT) |
Consider the following XML representation of a hierarchical (DAG) website, where element names correspond to hyperlink labels and id's correspond to nodes. <db id="1"> <a id="2"> <d id="5"> <g id="10"/> <h id="11"/> </d> <e id="6"> <g idref="11"/> <h id="12"/> </e> </a> <b id="3"> <f idref="5"/> <d id="7"> <g id="13"/> </d> </b> <c id="4"> <d id="8"> <g id="14"/> </d> <f id="9"> <g id="15"/> <h id="16"/> </f> </c> </db> Notice the presence of crosslinks in this hierarchy (e.g., from node 3 to node 5) making it a dag and not a tree. I'd like to prune all paths from the root to a leaf (nodes 10-16 above) not indexed under a given hyperlink label. For example, if I am given the hyperlink label "d", I'd like to produce the following XML representation of the transformed website: <db id="1"> <a id="2"> <d id="5"> <g id="10"/> <h id="11"/> </d> <e id="6"> <g idref="11"/> </e> </a> <b id="3"> <f idref="5"/> <d id="7"> <g id="13"/> </d> </b> <c id="4"> <d id="8"> <g id="14"/> </d> </c> </db> And finally, since "d" has been given, I'd like to collapse each hyperlink labeled "d", resulting in: <db id="1"> <a id="2"> <g id="10"/> <h id="11"/> <e id="6"> <g idref="11"/> </e> </a> <b id="3"> <f idref="10"/> <g id="13"/> </b> <c id="4"> <g id="14"/> </c> </db> The way I see it, the presence of crosslinks (e.g., from node 3 to 5 above) in the dag, require three processing steps to achieve the cumulative website transformation. (i) forward propagate from the root to find all leaf nodes indexed under "d" (ii) back-propagate from these leaf nodes to retain only the sequences indexing this set of leaves (iii) collapse hyperlinks labeled "d" Can all of these tasks be accommodated with only one stylesheet? I have stylesheets for each individual step (see below), but am not sure if my requirements can be accommodated in one stroke. (stylesheet for (i) above) <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:strip-space elements="*"/> <xsl:template match="node()[ancestor-or-self::d and count (child::node()) = 0]"> <xsl:value-of select="@id"/><xsl:text> </xsl:text> </xsl:template> <xsl:template match="text()"/> </xsl:stylesheet> (stylesheet for (ii) above) <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:strip-space elements="*"/> <xsl:template match="//*[descendant-or-self::node()[@id='10' or @id='11' or @id='13' or @id='14']]"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> (stylesheet for (iii) above) <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:strip-space elements="*"/> <xsl:template match="d"/> <xsl:template match="*|@*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> Of course, the hardcoded values in the above three stylesheets are for illustrative purposes only and will be included via parameters in the final implementation. Thank You and Best Regards, Saverio XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Count() elements in range, M. David Peterson | Thread | RE: [xsl] Problem sending node Arra, Joe Fawcett |
Re: [xsl] Count() elements in range, M. David Peterson | Date | RE: [xsl] calculating math:matrix l, Jarno . Elovirta |
Month |