BI Publisher conditional sorting issue - xslt

I am having trouble getting BI Publisher to sort based on my parameter. The parameter name in the data model is SORTBY and has two options (NAME, BIRTH_DATE). The values come from a "list of values" in the data model that match field names in the result set. I want the report to sort by the field selected by the user.
Below is my code in the RTF template using BI Pub tags:
<?param#begin:SORTBY?>
<?for-each:G_1?>
<?if:SORTBY='NAME'?>
<?sort:NAME;'ascending';'text'?>
<?end if?>
<?if:SORTBY='BIRTH_DATE'?>
<?sort:BIRTH_DATE;'ascending';'text'?>
<?end if?>
And here is the relevant resulting xsl-fo exported from Microsoft Word:
<xsl:for-each select=".//G_1" xdofo:ctx="3">
...
<xsl:if test=".//SORTBY = 'NAME'" xdofo:ctx="3">
<xsl:sort select="(.//NAME)[1]" order="ascending" data-type="text"/>
</xsl:if>
<xsl:if test=".//SORTBY = 'BIRTH_DATE'" xdofo:ctx="3">
<xsl:sort select="(.//BIRTH_DATE)[1]" order="ascending" data-type="text"/>
</xsl:if>
...
</xsl:for-each>

With some peer programming, a colleague of mine found the answer. The for-each does not like having an if (or a choose for that matter) inside. So, you have to assign the parameter to a variable and use the variable in the sort.
Outside the for loop:
<?xdoxslt:set_variable($_XDOCTX,'Order',SORTBY)?>
For loop:
<?for-each:G_1?>
<?sort:./*[name() = xdoxslt:get_variable($_XDOCTX,'Order')];'ascending';'text'?>

Related

Sharepoint row hyperlink

I'm new to this Sharepoint design.
I have a created a new list page and I want one entry of each row to hyperlink to a different page.
Sl Title Topic Subject
1 ABC TABC SABC
2 DEF TDEF TSABC
So, basically what i want is when I click on ABC under title column it should take me to a page & when I click on DEF they would take me to a different page which I have added by Clicking on Hyperlink.
The current scenario is whenever I add a Hyperlink all the Column entries for Title automatically take the same link.
I tried to change this bit and individually add for each entry to no avail.
<xsl:value-of select="$thisNode/#*[name()=current()/#Name]" /></xsl:when>
<xsl:otherwise>
The xxx is the link to the one of the List Pages I created.
Can someone please help me with this.
Thanks,
Sandip
Currently your xslt assigns the same path to all hyperlinks.
What you need to do is enter a path for each item. Store it in a dedicated column, for example called PageLink. Then you can use that column within your xslt:
<xsl:value-of select="$thisNode/#*[name()=current()/#Name]" />
</xsl:when>

Sharepoint XSL dropdown populated form a list

I'm trying to use a CEWP to display a list of items as a drop down list.
Specifically im trying to set the value to the url and then the title as the item shown in the drop down.
This is what I have so far
<xsl:template name="HubJumpTo" match="Row[#Style='HubJumpTo']" mode="itemstyle">
<select id="mySelect">
<xsl:for-each select="/item">
<option>
<xsl:attribute name="value"><xsl:value-of select="#value"/></xsl:attribute>
<xsl:value-of select="#name"/>
</option>
</xsl:for-each>
</select>
</xsl:template>
But the CEWP isn't showing any fields for me to specifiy which coloumn in the list should popul;ate value and name. Any suggestions why this might be?
The drop down isn't populating with anything and I assume this is because of this isse.
It might be a typo in your question (in which case, this answer will self-destruct...), but the problem may lie in this line
<xsl:for-each select="/item">
Because the xpath expression starts with a forward slash /, then this represents the document node, and so the expression is looking for the root element of the name item. There is only one root element in the document, and I guessing it is not called item!
You probably need to use a relative expression here, assuming item is a child element of the currently matched Row element.
<xsl:for-each select="item">
Your query seems bit ambiguous, you say CEWP i.e. "Content editor Webpart" how come you can use CEWP with XSLT for rendering list? it should be like, you need to add list view webpart and pass your custom xslt path to it.
also i see match="Row[#Style='HubJumpTo']" so do you have a column named 'Style'? and are there any rows with value "HubJumpTo"
DID this using SP services in the end.

Cannot get List Lookup XSL param to use in HTML tag using SharePoint 2010 Designer

So I am adding a span tag to a few column fields in a couple of view all forms in SP 2010 Designer that have a Hexadec string in them, i'm using an inline style to display a block with a coloured background rather than the hexadec itself, so pretty simple.
I successfully achieved this in the first view but in the second view I cannot seem to return the value to use in the inline style, below is the original xsl and the row param is thisNode. The only difference in the views is one is the view all for a custom list(this one is working) and the other is the view all for another custom list with the previous lists value as a Lookup column, the columns xsl value is below.
<xsl:value-of select="$thisNode/#*[name()=current()/#Name]" disable-output-escaping="yes" />
I have tried adding the {$thisNode/#*[name()=current()/#Name]} to the inline css but get nothing returned when I should see a block of colour when viewing the form. I have also tried other ways to get the value from the thisNode row but have had no luck, can anyone tell me what I should be doing or what I am doing wrong?
Worked it out!
So the first step was to remove the hyperlink around the Loopup column:
<xsl:value-of select="substring-before(substring-after($thisNode/#*[name()=current()/#Name],'>'), '<')" disable-output-escaping="yes"/>
This then shows the Lookup column value as text; so we can use this method to create another param or variable and add the value to our css parameter like so:
<xsl:param name="thisNode" select="."/>
<xsl:param name="thisColour" select="substring-before(substring-after($thisNode/#*[name()=current()/#Name],'>'), '<')"/>
<span style="display:block;background:{$thisColour};width:20px;height:20px;" title=""></span>
This then shows my Hexadec colour as a 20px block rather than the Hexadec code as text, so hope this helps anyone else with the same problem, enjoy!

Filtering DVWP with xslt with parameter from connected LVWP in Sharepoint Designer

My setup is as follows:
A custom page on a Sharepoint 2010 site with a list view web part and a Data view web part. When I select an item in the LVWP I want to filter the DVWP with a multi lookup field value. So I've connected to two web parts such that the DVWP gets the parameter from the LVWP. I filter the DVWP with the following:
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[contains($pDataAftaleID,concat(#ID,';#',#ID))]"/>
where pDataAftaleID is the parameter from the LVWP.
My problem is: Everything works well if the selected item from the LVWP has a value in the parameter field, but if it doesn't, Sharepoint doesn't seem to write the null/empty or zero value to the parameter and the filter parameter keeps the value from the last selected item in the LVWP with a value, and the DVWP therefore shows the items from some previous selected item and not "no items to show".
Is there some way to force the writing of the empty field, or is it possible to set the parameter to zero each time the DVWP loads? Any suggestions?
<xsl:variable name="Rows">
<xsl:choose>
<xsl:when test="/dsQueryResponse/Rows/Row[contains($pDataAftaleID,concat(#ID,';#',#ID))]">
<xsl:text>/dsQueryResponse/Rows/Row[contains($pDataAftaleID,concat(#ID,';#',#ID))]</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Please check if this or a variation of this works for you.

Can additional criteria be added to an XSL select that is generating a key?

I have an XML document of store locations which have a Type node indicating the type of store and an existing set of templates for adding a key to each Location based on it's state which then adds these to an HTML in order of their state.
What I need to do is exclude all of the states from display that do not have a Type of 1. It's easy enough in the for-each loop to skip display of those Locations but I end up with states displaying that have no values in them.
Here's the code inside the <select/> HTML tag:
<xsl:apply-templates select="$locations/descendant::Locations" mode="locations.list"/>
That template looks like this:
<xsl:template match="Locations" mode="locations.list">
<xsl:apply-templates select="Location[generate-id(.) = generate-id(key('state', State)[1])]" mode="locations.list.location"/>
</xsl:template>
The template it calls looks like:
<xsl:template match="Location" mode="locations.list.location">
<option value="state"><xsl:value-of select="normalize-space(State)"/></option>
<xsl:for-each select="key('state', State)">
<option value="{normalize-space(SiteKey)}"><xsl:value-of select="normalize-space(Location)/></option>
</xsl:for-each>
<option value=""/>
</xsl:template>
Ordinarily in the <xsl:apply-templates select="Location[generate-id(.) = generate-id(key('state', State)[1])]" mode="locations.list.location"/> I'd just indicate in the select that I was only interested in Locations that have a Type of '1' but I can't seem to find a way to insert that condition along with the key generation code.
Without seeing your entire input XML, this is a bit of guesswork:
<xsl:apply-templates
mode = "locations.list.location"
select = "Location[
generate-id(.)
=
generate-id(key('state', State)[Type = '1'][1])
]"
/>
Selects Locations nodes where the unique id equals the first Location with the current State.