Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Unique JS/HTML identifiers in DVWP

  Asked By: Felicia    Date: Nov 05    Category: Sharepoint    Views: 1548

I have a dataview web part which I would like to use twice on the
same page. It includes some client side javascript with references to
a few DIV tags. I am trying to use the following tag to ensure the
identifiers in the javascript and HTML are unique on the page.

<xsl:value-of select='ddwrt:GetVar("WPQ")'/>

so, in the XSL it would look something like this

<script language="javascript">
function transformXML<xsl:value-of select='ddwrt:GetVar("WPQ")'/>
(strXML, strXSL)

When I do a view source on the rendered page, everything seems to be
in order and I get something like this

<script language="javascript">
function transformXMLWPQ1(strXML, strXSL)

unfortunately, when I import the webpart onto the page a second time,
it also renders with the same "unique" number (WPQ1).

Is this approach correct to ensure HTML/JavaScript identifier
uniqueness? Does anyone know what the best place to readup on this
matter is? Any suggestions?



2 Answers Found

Answer #1    Answered By: Cory Brooks     Answered On: Nov 05

Why exactly are you using XSL to obtain the WPQ ID? If you only need this to happen on the client-side, instead, you can leave the token in its raw state and let SharePoint change the variables for you… so it would be more like this:

<script language="javascript">
function transformXML_WPQ_
(strXML, strXSL)

The source  will always have the token _WPQ_, but SharePoint will change it on the fly @ rendering time. Now, if you need it on the server-side portion… not completely sure how you’d accomplish that as I think all the token replacement and rendering happens after you can hook your code into it on the server-side.

Now where to get more info on it? Ha… that’s the hard part. Assuming WSS v2 (think it’s the same for the WSS v3 SDK), search for WPSC overview… first hit should be Web part  Page Services Component, and there’s an expando link Client-side programming using the WPSC which will give you more info that you’re looking for.

Answer #2    Answered By: Ruth George     Answered On: Nov 05

The purpose of this DVWP is to display information returned from a
webservice. The problem was the web  service returned an escaped XML
string which I have learned is a no-no and also seems to be the root
of much frustration to many people. Anyway, that can't be helped
because the data is coming from Microsoft. So my challenge to myself
was to do this all in the DVWP, no need to install a new webpart.
Seems like it could be easily repurposed for any web service.

My solution was to use to use a DVWP's XSL property to push down
three things to the client:

1) the returned SOAP payload from the web service defined in the
DVWP's DataQuery property,

2) a complete stylesheet (embedded in the DVWP's XSL property) for
the data returned by the web service, and

3) an HTML block containing three divs (hidden div  for XSL, hidden
div for XML, displayed div for results of XSL transformation) and
javascript to process the XSL.

This works great for the first webpart, but when I try to use this
framework again, the id's for the javascript  and divs are the
repeated so it doesn't work. Thus my attempt to build the WPQ into
the ID's.

The solution that you suggested doesnt work because the _WPQ_ is
being treated like a literal. (Unless I'm doing it wrong). The
workaround is easy (just change the XSL for each webpart  as it is

Didn't find what you were looking for? Find more on Unique JS/HTML identifiers in DVWP Or get search suggestion and latest updates.