Find level in navigation structure? - xslt

I have a sitecore 6 solution where the body background image changes depending on wich level you are currently on;
Home
- Subpage 1
-- Sub-subpage 1
-- Sub-subpage 2
--- Sub sub subpage 1
- Subpage 2
-- Sub-subpage 1
So i have a bg image for "Home", a bg image for "Subpage 1" and "Subpage 2" and a bg image for "Sub-subpage 1, 2" etc.
How would i check for the level in xslt?

It's kinda hard to say, as I'm not quite sure I've understood the question fully.
But one way would be to use:
<xsl:value-of select="count(ancestor::*)"/>
or
<xsl:value-of select="count(ancestor::node())"/>
See this page for an explanation of the difference:
http://www.dpawson.co.uk/xsl/sect2/N2193.html

Related

XSL-FO | FO: Tags are being removed

I'm currently using XSL for a work project and I'm facing an issue.
I'm trying to read values for a database that look like this:
<fo:block font-weight='bold>hello</fo:block>
and it seems that XSL is stripping the <fo:block> element because it gives me text only ( I only see Hello, not in bold, and it doesn't behave like a block element ). I feel like, somehow, that XSL interprets the value read from the DB as a string, and strip of the <fo> tags, leaving my with text only.
Any idea what could be done in order that my styling get preserved?
( Obviously this example have been simplified, the text to be displayed is longer than that )
EDIT : Self answered for future references
Based on the comments you want to change <xsl:value-of select='/fulfill-list/ticket-list/list-item/eventTicketConte‌​nt/xmlTicketContent/‌​ticketdescription'/> to <xsl:copy-of select='/fulfill-list/ticket-list/list-item/eventTicketConte‌​nt/xmlTicketContent/‌​ticketdescription'/> (or perhaps <xsl:copy-of select='/fulfill-list/ticket-list/list-item/eventTicketConte‌​nt/xmlTicketContent/‌​ticketdescription/node()'/>).
As first i wanted to thanks you all to have taken the time to answer me. I'm very very very glad to see SO community is such strong.
I have solved my problem this way :
<xsl:for-each select="/fulfill-list/ticket-list/list-item/eventTicketContent/xmlTicketContent/ticketdescription/node()">
<xsl:copy-of select="child::node()" />
</xsl:for-each>
I don't really know what happened beneath the hood and why the <fo> tags were removed, but they were. Looping through all of them and using <xsl:copy-of> did the trick.
Once again, a big thanks to y'all !

XSL fit single image and label to a page

I have an xsl document where I need to have a series of pages that each contain a single image caption and then a single image below it.
I do not know the exact image sizes ahead of time, but I want the caption to appear at the top of the page and then constrain the image to be no larger than the remainder of the height of the page or the width of the page (scaled uniformly if needed).
I have tried
<fo:block>
<fo:block>Image Caption Here</fo:block>
<fo:block>
<fo:external-graphic content-width="scale-down-to-fit" width="100%" content-height="scale-down-to-fit" height="100%" scaling="uniform">
</fo:block>
</fo:block>
And many combinations of widths/content-widths/heights/content-heights on the blocks and external graphic to no avail. Most often I get the image overflowing off the page either vertically or horizontally.
It is likely that it is necessary to add the attributes max-height and max-width to 100%.
<fo:external-graphic content-width="scale-down-to-fit" width="100%" content-height="scale-down-to-fit" height="100%" scaling="uniform" max-width="100%" max-height="100%">

Displaying language labels in sidebar facets

I asked this question a few days ago regarding on how to display the language labels in item view instead of its ISO version. How to apply these in sidebar facets and its search filters? I can't find the xslt for generating the displayed values in the sidebar facets.
In the image above, I would like to change the displayed values into:
English (5325)
French (432)
Chinese (8)
Khmer (5)
Japanese (2)
And then when clicking for example the sidebar facet for French, the displayed value in the search filter should be Language Equals French and not like the image below (Language Equals fr):
Thanks in advance.
What I have tried
I don't know if this is the most efficient way to do this so any advice would be appreciated.
<xsl:template
match="dri:list[#n='language']/dri:item/dri:xref/text()
| dri:list[#id='aspect.discovery.SidebarFacetsTransformer.list.language']/dri:item/text()
| dri:div[#id='aspect.discovery.SearchFacetFilter.div.browse-by-language-results']/dri:table/dri:row/dri:cell/dri:xref/text()">
<xsl:apply-templates select="*[not(name()='head')]"/>
<xsl:variable name="language">
<xsl:value-of select="substring-before(.,' (')"/>
</xsl:variable>
<xsl:for-each select=".">
<xsl:value-of select="concat(util:isoLanguageToDisplay($language),' (', substring-after(.,'('))"/>
</xsl:for-each>
</xsl:template>
The language labels of the dc.language.iso in my sidebar facets is now displaying properly both in the home page and search results.
When clicking View More:
My only problem now is this:
I don't know how to override the advanced search filters or if this is even possible.

Duplicate rows showing up as a result of Muenchian grouping in XSLT

I have an XSLT transformation that's returning a lot of duplicate items, as seen here:
after the snip, the second category shows up at the bottom:
This is what it's supposed to look like:
The way this report is structured is:
Project
> Phases (formatted with light grey background)
> Categories (if any, formatted with light blue background)
> Deliverables (formatted with white background)
> Sub-deliverables
The hierarchy works, but there's just too much. I'm not really sure what's going on at this stage. I'm using the Muenchian Method in XSLT 1.0.
Here is my input: http://pastebin.com/uJw1sPEQ
Here is my transformation: http://pastebin.com/7cJd6bj5
Only thing that looks strange is this line:
<xsl:apply-templates select="//Row[generate-id() = generate-id(key('Project-Phases', concat(ProjectNo, '|', Phase))[1][ProjectNo=current()/ProjectNo])]" mode="phase"/>
The [ProjectNo=current()/ProjectNo] part should not be attached to the key. It should instead be moved after the last ].

cfchart ignores my scalefrom value

I have the following codes in my page.
The style variable holds the custom style.
<cfchart chartheight="450" chartwidth="550" gridlines="9" yaxistitle="Score" scalefrom="20" scaleto="100" style="#style#" format="png" >
<cfchartseries query="variables.chart_query" type="scatter" seriescolor="##000000" itemcolumn="MyItem" valuecolumn="MyScore"/>
</cfchart>
Before I begin, please see chart_good.jpg. This is how I want my report to come up. On the x-axis, there will always be three items as long as at least one of them has values. If an item does not have any values (i.e. 2010), there would not be a marker in the chart.
The problem occurs only when only one item has value. Please see chart_bad.jpg. As you can see, 2008 and 2010 do not have any values; y-axis is now scaled from 0 to 100. I have tried setting one of the items (ex. 2008) a value of 0 or something off the chart; it would scale according to this off-the-chart value and the 2009 value. In short, I have to have at least two items with values between 20 and 100 in order for cfchart to scale from 20 to 100.
My question is, how can I correct the issue so that cfchart would ALWAYS scale from 20 to 100? I am running CF9.
What is inside your style variable?
I would suggest not using scaleFrom="" and scaleTo="" in the cfchart tag as they can be buggy sometimes. I believe that Coldfusion's cfchart tag attempts to scale the chart automatically to what it deems the best fit. Instead I would build the chart's minimum and maximum scales inside a frameChart tag.
Example of a style variable to build a chart
<cfsavecontent variable="style">
<?xml version="1.0" encoding="UTF-8"?>
<frameChart is3D="false" font="Arial-11-bold">
<frame xDepth="0" yDepth="0" outline="black" lightColor="#CCCCCC" darkColor="#CCCCCC"
wallColor="#CCCCCC" frameSize="5" dashSize="3" gridColor="#333333">
<background type="HorizontalGradient" maxColor="#828EB0"/>
</frame>
<!--- THE BREAD AND BUTTER
NOTE: if you use variables for the scaleMin and scaleMax
make sure to surround them with a cfoutput tag
--->
<yAxis scaleMin="20" scaleMax="100">
<!--- --------------------- --->
<labelFormat style="Currency" pattern="#,##0"/>
<parseFormat pattern="#,##0"/>
<titleStyle></titleStyle>
</yAxis>
<legend allowSpan="true" isVisible="false" placement="Bottom" valign="Bottom" foreground="black"
isMultiline="true">
<decoration style="None"/>
</legend>
<elements outline="black" shapeSize="40"/>
<popup background="#748BA6" foreground="white"/>
<paint palette="Modern" paint="Plain" isVertical="true"/>
<insets right="5"/>
</frameChart>
</cfsavecontent>
Then all you have to do is load the variable into the style attribute like you already mentioned.
<cfchart format="png" chartWidth="550" chartHeight="175" style="#style#">
Also a great resource to use, is the Webcharts program that will be in your C:/coldfusion/charting/ directory. Just open webcharts.bat, create your custom chart, copy the xml code into your style variable, and voila!
Make sure to remove the scaleTo= and scaleFrom= from your cfchart tag if you decide to go this route.