Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
function-available()
id()
key()
FUNCTION: generate-id
string =
generate-id
(
node-set
)
The
generate-id
function is used to generate a string value that identifies a node. The string will begin with an alphabetic character followed by several additional alphanumeric characters. Within the application of a stylesheet, each returned string value will be unique.
Unfortunately, the generated id has no relationship to any id attribute in the source document. (Therefore, you cannot use the
id
or
key
functions to find or set this value.)
The primary purpose of this function is to provide a mechanism to create links in the output document that use the id. For example, if this function returned the string h144d7 for a specified node, then the link to that node would be:
<a href="#h144d7">
node-set
The optional
node-set
argument defines the target node-set. If the node-set contains more than one node, then only the first node in the set will be considered. If the node-set is empty, the empty string will be returned. If this argument is omitted, then as a default, an id will be generated for the context node.
We use the
DevGuru Staff List XML file
for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_generateid.xsl"?>
and we name it: xslt_example_generateid.xml
We use
generate-id
twice in this example. We first create an index of links based upon the name, and then we create the name anchors.
Code for xslt_example_generateid.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="devguru_staff/programmer">
NAME: <a href="#{
generate-id(name)
}"><xsl:value-of select="name" /></a>
<hr />
</xsl:for-each>
<xsl:for-each select="devguru_staff/programmer">
NAME: <a name="{
generate-id(name)
}"><xsl:value-of select="name" /></a>
<p />
DOB: <xsl:value-of select="dob" />
<p />
AGE: <xsl:value-of select="age" />
<p />
ADDRESS: <xsl:value-of select="address" />
<p />
PHONE: <xsl:value-of select="phone" />
<hr />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Click to view output in separate window
- requires Internet Explorer Then click on links.
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information