Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

XSL Quick Reference

RSS
Modified on Thu, Aug 25, 2011, 8:26 AM by Administrator Categorized as (Favorites), Quick Reference, XML, XSL, and XPath

Table of Contents [Hide/Show]


   XML File Header
   XSL File Template
         Simple
         With Scripting
   Elements and Functions
         A
         B, C
         D
         E
         F
         G, H, I, J, K
         L
         M, N
         O, P, Q
         R, S
         T
         U, V, W, X, Y, Z
   Using Namespaces
      Sample XML Source
      Sample XSL Source

{outline||Part <1> - }

XML File Header

Place the following lines at the top of your XML file to have it automatically be transformed by the specifed XSL file when you view it in a web browser.

{copytext|XmlHeader}
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="MyXslFile.xsl"?> 

XSL File Template

Simple

{copytext|SimpleXsl}
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  version="1.0">

<xsl:template match="/"> 

<xsl:for-each select="*">
<xsl:value-of select="name()"/>
<br/>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

With Scripting

{copytext|XslWithScripting}
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:pj="urn:schemas-pgjasinski-batcave-net:pj"
  version="1.0">
<msxml:script language="VBScript" implements-prefix="pj">
Function msNote()
    msNote = CStr(Now())
End Function
</msxml:script>
<xsl:template match="/"> 

<xsl:for-each select="*">
<xsl:value-of select="name()"/>
<br/>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

Elements and Functions

Most Common: <xsl:stylesheet>, <xsl:template>, <xsl:for-each>, <xsl:choose>, <xsl:when>, <xsl:otherwise>, <xsl:value-of>, <xsl:call-template>

A

SyntaxDescription
<xsl:apply-imports>used to apply (invoke) the definitions and template rules of an imported stylesheet that normally might be overridden by the importing stylesheet (more)
<xsl:apply-templates select="expression" mode="qname"> defines a set of nodes to be processed, or by default selects all child nodes of the current node being processed, and finds a matching template rule to apply to each node in the set. Since each node in the node set is treated individually, it is possible for each node to have a different template applied to it. Note that a template rule is not actually returned, but rather, it manifests itself by how the node is displayed in the output (more)
<xsl:attribute name="qname" namespace="URI">creates an attribute node, defines a value, and adds it to the output (more)
<xsl:attribute-set name="qname" use-attribute-sets="qnames">defines and names a set containing zero or more <xsl:attribute> elements. Can only be a child of the <xsl:stylesheet> or the <xsl:transform> elements (more)

B, C

SyntaxDescription
boolean(value) Converts the argument to a Boolean and returns a true or false (more)
<xsl:call-template name="qname"> invokes a template by name (more)
<xsl:cdata>Creates and adds a new CDATA section which allows you to use markup elements without violating the XML well-formed requirements (more)
ceiling(number) returns the smallest integer that is equal to or larger than the numeric value of the argument (more)
<xsl:choose> used to make a choice when there are two or more possible courses of action, similar to IF/THEN blocks in other languages; used with <xsl:when> and <xsl:otherwise>. (more)
<xsl:comment>generates an HTML comment in the output (more)
concat(val1, val2, ...)concatenates the arguments in order (more)
contains(search-in,search-for)returns true if search-for argument is found within the search-in argument (more)
<xsl:copy use-attribute-sets="name-list">copies the current node, but no attributes or descendants, in the source document to the output (more)
<xsl:copy-of select="expression"/>inserts a complete, unabridged, duplicate copy of a node set or tree fragment into the output (more)
count(node-set)counts the number of nodes in a node set (more)
current()returns a node-set containing only the current node. Useful when the current node isn't the same as the context node (more)

D

SyntaxDescription
<xsl:decimal-format decimal-separator="character" digit="character" grouping-separator="character" infinity="string" minus-sign="character" name="qname" NaN="string" pattern-separator="character" percent="character" per-mille="character" zero-digit="character">defines the symbols and characters used by the format-number function to convert numbers to strings (more)
<xsl:define-template-set>defines a new set of templates (more)
document(uri, base-uri)locates an external XML document, parses that XML document, and returns a node-set that contains the root node (more)

E

SyntaxDescription
<xsl:element name="element-name" namespace="URI" use-attribute-sets="qname"> creates and names an element (node) that can appear in the output (more)
element-available('qname')determines if the XSLT processor will support the use of the XSLT element cited in the argument (more)
<xsl:entity-ref>creates and adds an entity reference node (more)
<xsl:eval>evaluates a script expression and generates a string that can appear in the output (more)

F

SyntaxDescription
<xsl:fallback>provides fallback code that can be run as an alternative when an XSLT processor fails to support an element (more)
false()returns the Boolean value of false (more)
floor(number)returns the largest integer that is equal to or is smaller than the numeric value of the argument (more)
<xsl:for-each select="expression"> loops through each node in a node set in its order of occurrence and applies the same template to each node (more)
formatnumber(number, format, decimal-format-qname)convert a single number into a string (more)
function-available('function-name')test whether the function specified in the argument is supported by the XSLT processor (more)

G, H, I, J, K

SyntaxDescription
generate-id(node-set)generates a string value that identifies a node (more)
id('value')returns a node-set containing zero or more nodes that have an attribute that match the argument (more)
<xsl:if test="expression">conditionally applies a template. No ELSE clause. (more)
<xsl:import href="uri">imports one stylesheet to another (more)
<xsl:include href="uri">includes one stylesheet to another (more)
<xsl:key match="pattern" name="qname" use="expression">declares a named key that can be used by the key function in expressions and patterns (more)
key(name,value)returns a node-set that contains all of the nodes in an XML document that match the name-value pair specified (more)

L

SyntaxDescription
lang(language)tests whether the language specified by the argument matches the language of the context node (more)
last()returns the position number assigned to the last node in the current node list that is being processed by an <xsl:for-each> or <xsl:apply-templates> element (more)
local-name(node)returns the local part of a qname (or an empty string if there is no local name) (more)

M, N

SyntaxDescription
<xsl:message terminates="yes"|"no">used to report errors by displaying a text message and related information of interest in the output (more)
name(node)returns the qname of the node (more)
<xsl:namespace-alias stylesheet-prefix="prefix" result-prefix="prefix">replaces a namespace in a stylesheet with a different namespace for use in the output (more)
namespace-uri(node)returns a string that is the namespace URI of the specified node (or the current node if no node is specified) (more)
<xsl:node-name>adds the current node name to output (more)
normalize-space(string)returns a string in which all of the preceding and trailing white space has been removed, and in which all internal sequences of white-space is replaced with one space. If the argument is omitted, the text of the context node is used. (more)
not(condition)returns a Boolean negation of the argument (more)
<xsl:number count="pattern" format="string" from="pattern" grouping-separator="character" grouping-size="number" lang="languagecode" letter-value={ "alphabetic" | "traditional" } level= {"any" | "multiple" | "single"} value="expression">either (1) determines the sequence number for the current node, or (2) formats a number for display (more)
number(value)converts the argument to a number. If the argument is omitted, the text of the context node is used. (more)

O, P, Q

SyntaxDescription
<xsl:otherwise>optional child of a <xsl:choose> node, containing the ELSE clause (more)
<xsl:output cdata-section-elements="namelist" doctype-public="string" doctype-system="string" encoding="string" indent= {"yes" | "no"} media-type="mimetype" method={"html" | "name" | "text" | "xml"} omit-xml-declaration={"yes" | "no"} standalone={"yes" | "no"} version="version_number">defines the format of the output created by the stylesheet by setting one or more of ten optional attributes (more)
<xsl:param name="qname" select="expression">declares a local or global parameter and gives it a name and a default value (more)
<xsl:pi>Generates a processing instruction in the output (more)
position() returns the position number in the current node list of the node that is currently being processed by an <xsl:for-each> or <xsl:apply-templates> (more)
<xsl:preserve-space elements="names">used to keep white-space-only nodes in the output (more)
<xsl:processing-instruction name="process-name">writes a processing instruction to the output (more)

R, S

SyntaxDescription
round(number)rounds a number to its closest integer (more)
<xsl:script language="lang" implementation-prefix="prefix"> (msxml:script)creates a scripting area in a template in which you can declare global variables and define functions (more)
<xsl:sort case-order="upper-first" | "lower-first" data-type={"number" | "qname" | "text"} lang="language-code" order={"ascending" | " descending"} select="expression"> defines a sort key which determines the order in which selected nodes are processed by the <xsl:for-each> or <xsl:apply-templates> elements (more)
starts-with(string, substring)returns a Boolean indicating whether the string argument starts with the substring specified (more)
string(expression)converts the specified expression to a string. If the expression is omitted, the context node is used. (more)
string-length(string)returns the number of characters in a string (more)
<xsl:strip-space elements="names">removes white-space-only nodes so that they do not appear in the output (more)
<xsl:stylesheet version="version_number" id="unique_id" exclude-result-prefixes="list" extension-element-prefixes="list">contains all other XSLT elements and delimits the start and stop of the code in an .XSL program (synonymous with <xsl:transform>) (more)
substring(string, start, length)returns the portion of a string that starts at the designated starting position and continuing for the designated number of characters (more)
substring-after(string, substring)returns a portion out of a string that occurs after a substring (more)
substring-before(string, substring)returns a portion out of a string that occurs before a substring (more)
sum(node-set)adds and returns the total value of a set of numeric values within a node-set (more)
system-property({'xsl:version' | 'xsl:vendor' | 'xsl:vendor-url'})returns information about the XSLT processor environment (more)

T

SyntaxDescription
<xsl:template match="pattern" mode="qname" name="qname" priority="number">defines a template that can be applied to a node to produce a desired output (more)
<xsl:text disable-output-escaping={"yes" | "no"}>adds literal text to the output (more)
<xsl:transform version="version_number" id="unique_id" exclude-result-prefixes="list" extension-element-prefixes="list">contains all other XSLT elements and delimits the start and stop of the code in an .XSL program. (synonymous with <xsl:stylesheet>) (more)
translate(value, old, new)replaces all occurences of one string within another (more)
true()returns a Boolean true (more)

U, V, W, X, Y, Z

SyntaxDescription
unparsed-entity-uri('name')returns an absolute URI (Uniform Resource Identifier) that gives access to declarations of unparsed entities in the Document Type Definition (DTD) of the source document (more)
<xsl:value-of select="expression" disable-output-escaping={"yes" | "no"}> writes in the result tree a string representation of the value assigned to a specified node (more)
<xsl:variable name="qname" select="expression>declares a local or global variable and gives it a name and a value (more)
<xsl:when test="expression"> child of the <xsl:choose> element. If the expression is true, then the code within the element is executed. If false, testing of expressions continues with the next element. (more)
<xsl:with-param name="qname" select="expression">sets the explicit value of a named parameter when using the <xsl:apply-templates> and the <xsl:call-template> elements (more)

Using Namespaces

Sample XML Source

Note the default namespace.

<Report 
    xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition"
    xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
    >
  . . .
  <DataSets>
    <DataSet Name="Main">
    . . .
    <DataSet Name="FYear">
    . . .
    <DataSet Name="FMonth">
    . . .
  </DataSets>
</Report>

Sample XSL Source

This XSL will list the name of each dataset. We define the namespace alias ssrs to refer to the default namespace of the XML document. We can then use the ssrs alias in XPaths.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:ssrs="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition"
  version="1.0">
  
    <xsl:template match="/"> 
        <xsl:for-each select="ssrs:Report/ssrs:DataSets/ssrs:DataSet">
            <xsl:value-of select="@Name"/>
        </xsl:for-each>
    </xsl:template>
    
</xsl:stylesheet>

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2018, Patrick Jasinski.