Export to XML from SSRS/Visual Studio with XSLT -
Export to XML from SSRS/Visual Studio with XSLT -
i trying create xml using xslt file exporting rdl file via visual studio 2008 r2 (bids) or ssrs.
the export results in next xml code
<?xml version="1.0" encoding="utf-8"?> <report xsi:schemalocation="testreport http://reportserver?%2ftestreport&rs%3aformat=xml&rc%3aschema=true" name="testreport" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="testreport"> <productlist> <details_collection> <details> <id>602</id> <title>302</title> </details> <details> <id>603</id> <title>303</title> </details> </details_collection> </productlist> </report> from another post here on site got next xslt code:
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" exclude-result-prefixes="xsi"> <xsl:output method="xml" indent="yes" encoding="utf-8" /> <!-- rule suppress undesired nodes --> <xsl:template match="report|productlist|details_collection"> <xsl:apply-templates/> </xsl:template> <!-- rule rename details node --> <xsl:template match="details"> <item> <xsl:apply-templates/> </item> </xsl:template> <!-- rule re-create else --> <!-- see http://stackoverflow.com/questions/857010/xsl-avoid-exporting-namespace-defintions-to-resulting-xml-documents--> <!-- see http://stackoverflow.com/questions/14166259/xslt-default-template-confusion --> <xsl:template match="*|@*"> <xsl:element name="{name()}"> <xsl:apply-templates/> </xsl:element> </xsl:template> <!-- rule start conversion , provide wrapper tags --> <xsl:template match="/"> <rss version="2.0"> <channel> <xsl:apply-templates/> </channel> </rss> </xsl:template> </xsl:stylesheet> when applying xslt, export results in next xml code
<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <report> <productlist> <details_collection> <details> <id>602</id> <title>302</title> </details> <details> <id>603</id> <title>303</title> </details> </details_collection> </productlist> </report> </channel> </rss> what not seeing here? "report", "productlist","details_collection" should not appearing in output , "detail" element should named "item". seems if elements cannot adressed names (the template matches elements seem working "/", "*" , "/*"). never achieved adress 1 specific element name.
i expecting this:
<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <item> <id>602</id> <title>302</title> </item> <item> <id>603</id> <title>303</title> </item> </channel> </rss> can help me? cheers commx
your input xml in namespace, is, default namespace:
<report xmlns="testreport"> all descendant elements belong namespace. matters in case element report , 1 called {testreport}report (the {} tell namespace present) exclusively different elements.
so, if template matches
<xsl:template match="report"> it triggered if element named "report" found in no namespace. instead, if need address names of specific elements , if in namespace, need declare namespace in xslt stylesheet , prefix element names:
<xsl:stylesheet xmlns:tst="testreport"> <xsl:template match="tst:report"> <!--...--> </xsl:template> <!--...--> </xsl:stylesheet> you observe that
the template matches elements seem working "/", "*" , "/*"
because patterns generic ones not create utilize of specific element names need prefixing.
xslt stylesheet
more details: no need redeclaring xsi namespace in stylesheet - have omitted it. also, processors maintain whitespace nodes results in output beingness badly formatted - have added xsl:strip-space business relationship this.
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0" xmlns:tst="testreport" exclude-result-prefixes="tst"> <xsl:output method="xml" indent="yes" encoding="utf-8" /> <xsl:strip-space elements="*"/> <!-- rule suppress undesired nodes --> <xsl:template match="tst:report|tst:productlist|tst:details_collection"> <xsl:apply-templates/> </xsl:template> <!-- rule rename details node --> <xsl:template match="tst:details"> <item> <xsl:apply-templates/> </item> </xsl:template> <!-- rule re-create else --> <xsl:template match="*|@*"> <xsl:element name="{name()}"> <xsl:apply-templates/> </xsl:element> </xsl:template> <!-- rule start conversion , provide wrapper tags --> <xsl:template match="/"> <rss version="2.0"> <channel> <xsl:apply-templates/> </channel> </rss> </xsl:template> </xsl:stylesheet> xml output
<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <item> <id>602</id> <title>302</title> </item> <item> <id>603</id> <title>303</title> </item> </channel> </rss> xml visual-studio xslt reporting-services xslt-1.0
Comments
Post a Comment