Show navigation | Frontpage | Contact us | Sitemap

Data Query XSL Definitions, XPath examples

The following demonstrates common XPath tasks.

Runtime values navigation
Data Query Navigation

Runtime values navigation

The runtime values comes from the IIS' ASP objects or from Composite - they enable you to read form data, cookies, session variables, Composite state info (current document ID etc.) and more.

QueryString

/xml/RuntimeValues[@name='QueryString']/Value[@name='customer_id']/@value
Returns the value of the GET parameter customer_id

Form

/xml/RuntimeValues[@name='Form']/Value[@name='comments']/@value
Returns the value of the POST parameter comments

ServerVariables

/xml/RuntimeValues[@name='ServerVariables']/Value[@name='REMOTE_ADDR']/@value
Returns the value of the Server variable REMOTE_ADDR (the IP of the visitor). You can use the same names as the Request.ServerVariables collection offers.

Cookies

/xml/RuntimeValues[@name='Cookies']/Value[@name='visitor_name']/@value
Returns the value of the Cookie visitor_name

Session

/xml/RuntimeValues[@name='Session']/Value[@name='login']/@value
Returns the value of the Session variable login. Sessions must be enables on the IIS site in order for this to work.

Application

/xml/RuntimeValues[@name='Application']/Value[@name='current_online']/@value
Returns the value of the Application variable current_online.

Composite

/xml/RuntimeValues[@name='Composite']/Value[@name='DocumentID']/@value
Returns the value of the document ID of the page being rendered.

The following Composite values (@name) can be used:

  • DocumentID
    Number (The ID of the document being rendered).
  • TemplateID
    Number (The Template ID of the document being rendered).
  • StatusID
    Number (1=public | 2=proposed | 3=working copy)
  • IsPreview
    Boolean (true | false). True when the document is rendered via the administrative module.
  • LCID
    Number (The LCID of the current documents language, i.e. 1033 for English (US))
  • Identifier
    String
  • TemplateGroupID
    Number (The TemplateGroup ID of the document being rendered).
  • IID
    String (The Instance ID of the running site, i.e. MyCompanyGuest)

Data Query Navigation

XML data from the Data Queries (see Data Query Definitions) are addressed by the following XPath:

/xml/Query[@name='<the query name>']
or
/xml/Query[@id='<the query id>']

The XPath beyond this point depends on the query. Below are examples XPaths to common query results:

Std. query (Provider specific default behavior)

If a query is defined as using the "Provider specific default behavior", ADO will create XML like:
  <xml>
    <rs:data>
      <z:row last_name="Johnson" tool="22" />
      <z:row last_name="Nielsen" tool="14" />
    </rs:data>
  </xml>

This XML represents a query result like SELECT last_name, tool FROM members:

last_name tool
Johnson 22
Nielsen 14


The XML that ADO returns is located within the Query node described above. Hence, the following XPath retrieves the Johnson and Nielsen values:
  /xml/Query[@id='<the query id>']/xml/rs:data/z:row/@last_name

The following XPath selects the tool value for the record with the last_name Johnson:
  /xml/Query[@id='<the query id>']/xml/rs:data/z:row[@last_name='Johnson']/@tool

XML Query (Provider returns XML)

The XPath depends on the XML that is returned from the provider - use the Execute Query on the Data Query Definitions plug-in to see the exact XML.

The following example show what MS SQL Server 2000's "FOR XML" clause returns, when called from the Data Query Definitions plug-in:

SELECT Member.last_name, Member.tool, Location.title
FROM   Member INNER JOIN Member_Location 
          
ON Member.id = Member_Location.member_id
       INNER JOIN Location
          ON Location.id = Member_Location.location_id
FOR XML AUTO

<xml>
  <Query name='the query name' id='the query id'>
    <Member last_name='Johnson' tool='22'>
      <Location title='The top of the world'/>
      <Location title='The Hilton Royal Halls'/>
      <Location title='The Super Bowl'/>
    </Member>
    <Member last_name='Nielsen' tool='14'>
      <Location title='The Boowaa In'/>
    </Member>
  </Query>
</xml>

The following XPath selects all last_name values:
  /xml/Query[@id='<the query id>']/Member/@last_name

The following XPath selects all Location.title values for Member records with tool = 22:
  /xml/Query[@id='<the query id>']/Member[@tool='22']/Location/@title

My modules


© 2008 Composite A/S, Danmark
Tlf: +45 39 15 76 00 | info@composite.net
Composite A/S er Microsoft Certified Partner
Composite CMS overholder standarden for valid CSS
Composite CMS overholder standarden for valid XHTML 1.0
Printet fra http://www.composite.net/composite-581.htm
Findes på denne sti: Composite Developer | 3.x technologies | XSLT | Plug-in documentation | Data Query XSL Definitions | XPath Examples