Xslt Unique Key Generate Id
Produces two BB elements, whose bAttr2 attributes have the desired set of distinct values (if you want just the string values of the attributes, just use xsl:apply-templates or xsl:for-each for that expression). The xsl:key element is a top-level element which declares a named key that can be used in the style sheet with the key function. Note: A key does not have to be unique!
-->In an XML Schema definition language (XSD) schema, you can specify constraints (unique, key, and keyref constraints) and relationships (using the msdata:Relationship annotation). This topic explains how the constraints and relationships specified in an XML Schema are interpreted to generate the DataSet.
In general, in an XML Schema, you specify the msdata:Relationship annotation if you want to generate only relationships in the DataSet. For more information, see Generating DataSet Relations from XML Schema (XSD). You specify constraints (unique, key, and keyref) if you want to generate constraints in the DataSet. Note that the key and keyref constraints are also used to generate relationships, as explained later in this topic.
Generating a Relationship from key and keyref Constraints
Instead of specifying the msdata:Relationship annotation, you can specify key and keyref constraints, which are used during the XML Schema mapping process to generate not only the constraints but also the relationship in the DataSet. However, if you specify msdata:ConstraintOnly='true'
in the keyref element, the DataSet will include only the constraints and will not include the relationship.
The following example shows an XML Schema that includes Order and OrderDetail elements, which are not nested. The schema also specifies key and keyref constraints.
The DataSet that is generated during the XML Schema mapping process includes the Order and OrderDetail tables. In addition, the DataSet includes relationships and constraints. The following example shows these relationships and constraints. Note that the schema does not specify the msdata:Relationship annotation; instead, the key and keyref constraints are used to generate the relation.
In the previous schema example, the Order and OrderDetail elements are not nested. In the following schema example, these elements are nested. However, no msdata:Relationship annotation is specified; therefore, an implicit relation is assumed. For more information, see Map Implicit Relations Between Nested Schema Elements. The schema also specifies key and keyref constraints.
The DataSet resulting from the XML Schema mapping process includes two tables:
Generate Unique Id
The DataSet also includes the two relationships (one based on the msdata:relationship annotation and the other based on the key and keyref constraints) and various constraints. The following example shows the relations and constraints.
If a keyref constraint referring to a nested table contains the msdata:IsNested='true' annotation, the DataSet will create a single nested relationship that is based on the keyref constraint and the related unique/key constraint.
See also
-->Returns a string that uniquely identifies the node in the node-set argument that is first in document order.
Remarks
The unique identifier must consist of ASCII alphanumeric characters and must start with an alphabetic character. Thus, the string is syntactically an XML name. There is no guarantee that a generated unique identifier will be distinct from any unique IDs specified in the source document. If the node-set argument is empty, the empty string is returned. If the argument is omitted, it defaults to the context node.
Example
XML File (data.xml)
XSLT File (sample.xsl)
This is the formatted output:
When you click the left button in Internet Explorer, an alert box displays 'IDAHAGJD'.
When you click the right button in Internet Explorer, an alert box displays 'IDAPAGJD'.
Notice that the ID value is generate at run-time. Therefore, the specific values may vary in different invocation of the transformation.
This is the processor output:
Javascript Generate Id
<html>
<body><button>Gambardella, Matthew</button>
<button>Ralls, Kim</button></body>
</html>