xsl-list
[Top] [All Lists]

Re: Generating Unique ID

2005-12-06 08:31:45

Arun,

You can take a look at:

http://www.electronicsolutionsco.com/XMLEdit/XSLT/XMLEditBasicForm.xslt
http://www.electronicsolutionsco.com/XMLEdit/XSLT/XMLEditBaseElements.xslt

In XMLEditBasicForm.xslt, I create heirarchical id's for div and span elements. Search for "id=" in the file and you'll find text such as:

 div id="{$div_name}"
 span id="{$span_name}"

where $div_name was formed from an id created by the template function found in XMLEditBaseElements.xslt:

 create_path()

create_path() creates addresses (id's) based upon the hierarchical location of an element within the XML file being transformed. (The id's are heirarchical but not necessarily sequential, e.g. there may be gaps in the numbering.) If there is a reasonable correlation between the structure of the XML file and the resulting HTML, this may work for you. If not, it may at least give you some ideas. FAIR WARNING: My implementation of create_path(), to put it mildly, sucks. Despite my efforts to do a fully recursive version, I could never get it to work. So in the interest of expediency, I did a version which I believe nests to about 5 or 6 levels, but it is brute force and not at all elegant. Feel free to improve upon it as you may.

These files are part of the XMLEdit demo found at:

 http://www.electronicsolutionsco.com/XMLEdit

XMLEdit is a limited function CMS where content is stored in XML files and manipulated through xslt and javascript to change the public website. You can edit the XML in a strictly defined manner and then preview and publish the page. The hierarchical id's are used while editing the XML content. You can see the xslt that uses these id's in action by editing:

 http://www.electronicsolutionsco.com/XMLEdit/xml/demo.xml

Underneath the "Preview Page" button, near the bottom of the page, are two buttons to view either the underlying XML data for the page or the transformed HTML that created the page.

Hope this helps.

--
Steve Rosenberry
Sr. Partner

Electronic Solutions Company -- For the Home of Integration
http://ElectronicSolutionsCo.com

(610) 670-1710


Arun Sinha wrote:

Hi Ragulf,

Actualy the HTML page that I am producing has a drilldown facility.
When the page is called for the first time only the level one data is shown with closing folder
picture. When the folder is clicked then the next level data is shown.

To get this working the javascript, that we have, needs IDs like that.

Best Regards.

Arun




From: "Ragulf Pickaxe" <ragulf(_dot_)pickaxe(_at_)hotmail(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Generating Unique ID
Date: Tue, 06 Dec 2005 09:35:23 +0100

Hi Arun,

Why do you need the id to contain its parents id as well?

You have a function, generate-id(), which generates a unique id on a node.

If you need an id like what you state, you will need to do something like this (a variation of identity template):

<xsl:template match="*">
 <xsl:variable name="special-id">
   <xsl:for-each select="ancestor-or-self::*">
     <xsl:value-of select="generate-id(.)"/>
   </xsl:for-each>
 </xsl:variable>
 <xsl:copy>
   <xsl:copy-of select="@*"/>
<xsl:attribute name="ID"><xsl:value-of select="$special-id"/></xsl:attribute>
   <xsl:apply-templates/>
 </xsl:copy>
</xsl:template>

Is the above what you need?

Regards,
Ragulf Pickaxe :-)

_________________________________________________________________
Find det, du søger på MSN Søg http://search.msn.dk


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>