Solved

XSLT issue with SSRS 2008 (works fine with 2008 R2)

Posted on 2010-11-12
11
2,241 Views
Last Modified: 2012-06-27
Hi

I use SSRS + XSLT to generate XML and this code works perfectly when I use BIDS and when I use deployed report to SSRS 2008 R2
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:lgw="LineGraphWidget"
     exclude-result-prefixes="lgw"
    version="1.0">
	<xsl:output indent="yes"/>
	<xsl:template match="/">
		<xsl:element name="graphs">
			<xsl:element name="graphconfig">
				<xsl:attribute name="colorSet">
					<xsl:value-of select="'mixColors'"/>
				</xsl:attribute>
				<xsl:attribute name="minVal">
					<xsl:value-of select="0"/>
				</xsl:attribute>
				<xsl:attribute name="maxVal">
					<xsl:value-of select="100"/>
				</xsl:attribute>
				<xsl:attribute name="inte">
					<xsl:value-of select="50"/>
				</xsl:attribute>
				<xsl:apply-templates select="//lgw:Details1"/>
			</xsl:element>
			<xsl:element name="graphholder"> 
				<xsl:apply-templates select="//lgw:ResultCategoryNode"/>
			</xsl:element>
		</xsl:element>
	</xsl:template>
	<xsl:template match="lgw:Details1">
		<xsl:element name="graph">
			<xsl:attribute name="name">
				<xsl:value-of select="@ConfigMonth"/>
			</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="lgw:ResultCategoryNode">
		<xsl:element name="{concat('graph', position())}">
			<xsl:attribute name="Name">
				<xsl:value-of select="@ResultCategoryFieldCategory"/>
			</xsl:attribute>
			<xsl:apply-templates select=".//lgw:ResultDetailsNode">
			</xsl:apply-templates>
		</xsl:element>
	</xsl:template>
	<xsl:template match="lgw:ResultDetailsNode">
		<xsl:element name="graph">
			<xsl:attribute name="value">
				<xsl:value-of select="@ResultFieldNoOfJobs"/>
			</xsl:attribute>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

Open in new window


However it doesn't work properly with 2008 I get certain elements but no data related to XML at all (The report itself runs fine)

For comparison less effective approach works fine both on 2008 and 2008 R2
See below
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:lgw="LineGraphWidget"
     exclude-result-prefixes="lgw"
    version="1.0">
	<xsl:output indent="yes"/>
	<xsl:template match="/">
		<graphholder>
			<xsl:for-each select="(//*[local-name()='ResultCategoryNode'])">

				<xsl:variable name="MyCategory" select="@ResultCategoryFieldCategory" />

				<xsl:element name="{concat('graph', position())}">
					<xsl:attribute name="Name">
						<xsl:value-of select="@ResultCategoryFieldCategory"/>
					</xsl:attribute>

					<xsl:for-each select="(//*[local-name()='ResultDetailsNode'])[@JobStatus=$MyCategory]">
						<graph>
							<xsl:attribute name="Value">
								<xsl:value-of select="@ResultFieldNoOfJobs"/>
							</xsl:attribute>
						</graph>
					</xsl:for-each>
				</xsl:element>

			</xsl:for-each>
		</graphholder>

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

Open in new window


There are no differences between XML files (2008/2008 R2) apart from slight change in server path which is expected.

I suspect/hope 2008 doesn't like only certain elements of the code and some modifications might work.

If anyone had similar experience in the past or have suggestions I would appreciate your help.

Many thanks
Emil
0
Comment
Question by:itcouple
  • 6
  • 5
11 Comments
 
LVL 10

Author Comment

by:itcouple
ID: 34118591
Hi

I have replaced
//lgw:
with
//*[local-name()='

and that seem to resolve the issue.

Any comments about the incompatibility core reasons are still welcome :)

Regards
Emil
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34118676
There are more differences between your two XSLTs other than the namespace difference.

The first thing you should test is namespace dependence.
As I told you in the other question, I am very suspicious about a default namespace switch

CAn you test the below stylesheet to work with both versions of the reporter?

If they do, then the conclusion is that the reporter changed the namespace of your XML
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
        <xsl:element name="graphs">
            <xsl:element name="graphconfig">
                <xsl:attribute name="colorSet">
                    <xsl:value-of select="'mixColors'"/>
                </xsl:attribute>
                <xsl:attribute name="minVal">
                    <xsl:value-of select="0"/>
                </xsl:attribute>
                <xsl:attribute name="maxVal">
                    <xsl:value-of select="100"/>
                </xsl:attribute>
                <xsl:attribute name="inte">
                    <xsl:value-of select="50"/>
                </xsl:attribute>
                <xsl:apply-templates select="//*[local-name() ='lgw:Details1']"/>
            </xsl:element>
            <xsl:element name="graphholder"> 
                <xsl:apply-templates select="//*[local-name() ='ResultCategoryNode']"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>
    <xsl:template match="*[local-name() ='Details1']">
        <xsl:element name="graph">
            <xsl:attribute name="name">
                <xsl:value-of select="@ConfigMonth"/>
            </xsl:attribute>
        </xsl:element>
    </xsl:template>
    <xsl:template match="*[local-name() ='ResultCategoryNode']">
        <xsl:element name="{concat('graph', position())}">
            <xsl:attribute name="Name">
                <xsl:value-of select="@ResultCategoryFieldCategory"/>
            </xsl:attribute>
            <xsl:apply-templates select=".//*[local-name() ='ResultDetailsNode']">
            </xsl:apply-templates>
        </xsl:element>
    </xsl:template>
    <xsl:template match="*[local-name() ='ResultDetailsNode']">
        <xsl:element name="graph">
            <xsl:attribute name="value">
                <xsl:value-of select="@ResultFieldNoOfJobs"/>
            </xsl:attribute>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 10

Author Comment

by:itcouple
ID: 34119148
Hi

I tried the code and it worked in both cases.

When I export the report as XML without XSL they look pretty the same (see attached)

Does it mean it changes something after that point?

Regards
Emil
XSLTIssue.txt
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 34119193
So,  if my latest code works in both cases, there is a namespace issue.
Both snippets you posted point to a different schema, but still in the same namespace
So the XSLT result should be equal

This means indeed that the XML is altered by the report generator prior to running the XSLT
That is BAD and I consider that a major flaw

Could you do me a favour please?
Can you run the below XSLT on both report servers?
It will return to me a copy of the input (it is an identity transformation)
If you could then show me the two results, I can see what alterations the report server made prior to XSLT
I am suspicious that the earlier version of the software had a bug that is fixed
Browsing the web for detail, I find too much code having local-name() in there.
That must mean something (likely a bug in the SSRS XSLT)
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34119196
sorry, forgot the XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output indent="yes"/>
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 10

Author Comment

by:itcouple
ID: 34119283
Hi

Here is output in 2008
<Report Name="LineGraphWidget_Test">

and 2008 R2
Report Name="LineGraphWidget_Test" xmlns="LineGraphWidget_Test">

It does lose the namespace... I will check if it was raised on connect, maybe they fix that in SP (I doubt it: p)

Many thanks for solving the mistery!
Emil
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34119480
welcome,

I did some reading and found out that messing up the namespace is a bug found right after releasing 2008.
(from what I understand)

Another possibility is that the config for both is different
aparently: "try setting the "OmitSchema" deviceInfo to true in your rsreportserver.config"
if you do that the namespace gets dropped.
Could be that one setting has this as "true" the other as "false"

If that is teh case. I recommend that you set it to true
so you don't have to bother with the namespace and use
                        <xsl:apply-templates select="//Details1"/>
instead of
                        <xsl:apply-templates select="//lgw:Details1"/>

For readibility and performansce, it would be good to play around a bit with the namespace settings in the config,
so your XSLT could be cleaner
0
 
LVL 10

Author Comment

by:itcouple
ID: 34120687
Gertone,

I will be honest with you..... I won't bother :) It is working currently on 2008 and 2008 R2 and that is good enough for me.

Just out of interested I am working on something and came across limitations of SSRS/SSAS and I wonder if you have any ideas how to make it work.....

I have SSRS Report which extract field data based on this
<?xml version="1.0" encoding="utf-8"?><Field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="Level" UniqueName="[Dim Job Status].[Job Status].[Job Status]" />

The problem I have is that I want to make my query (MDX) generic so I can issue different MDX using the same report/XSLT. The problem I have is that I cannot neither rename my field to something generic using MDX nor change that in SSRS designer (dataset). So my only hope is too look into this understabloe for me  code which is generate automatically and hope that I can modify it for me own needs....

Again many thanks for sharing your knowledge!
Emil
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34120755
usualy "*" is your friend if you want to do that
"*" is a wildcard for elements
"*[1]" would be the first child element

you can play with that and come up with a generic XSLT if you want
0
 
LVL 10

Author Comment

by:itcouple
ID: 34121294
Thanks I tried that.... and unfortunatelly didn't work. There is type in this code with Level but also Measure (If I could just use 'Set; that would work)..... Anyway I found ugly solution where I just add fields I want with XML for all my queries and during execution there are ignored and the report still runs. Ugly but should be fine for the time being.

Regards
Emil
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34121347
OK, cheers
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question