I have an ecommerce cart which generates the XML at runtime. I have access to the XSL stylesheet which styles the actual XML.
I would like to display product category images in the menu. Is there an example of running a query within an xsl file that you could show me?
I cant see where its pulling the category data from?
can you help?
<?xml version="1.0" standalone="yes" ?>
<!-- ###################################################################################################### -->
<!-- Copyright AspDotNetStorefront.com, 1995-2009. All Rights Reserved. -->
<!-- http://www.aspdotnetstorefront.com -->
<!-- For details on this license please visit the product homepage at the URL above. -->
<!-- THE ABOVE NOTICE MUST REMAIN INTACT. -->
<!-- ###################################################################################################### -->
<package version="2.1" displayname="Categories" debug="false" includeentityhelper="true">
<PackageTransform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:param name="CategoryID">
<xsl:choose>
<xsl:when test="/root/System/PageName = 'showmanufacturer.aspx' or /root/System/PageName = 'showsection.aspx' or /root/System/PageName = 'showdistributor.aspx' or /root/System/PageName = 'showvector.aspx' or /root/System/PageName = 'showgenre.aspx'">0</xsl:when>
<xsl:when test="/root/System/PageName = 'showcategory.aspx' and boolean(/root/QueryString/categoryid)">
<xsl:value-of select="/root/QueryString/categoryid"/>
</xsl:when>
<xsl:when test="(/root/System/PageName = 'showcategory.aspx' or /root/System/PageName = 'showproduct.aspx') and boolean(/root/Cookies/LastViewedEntityInstanceID) and /root/Cookies/LastViewedEntityName = 'Category'">
<xsl:value-of select="/root/Cookies/LastViewedEntityInstanceID"/>
</xsl:when>
<xsl:otherwise>
0
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="AncestorID">
<xsl:for-each select="/root/EntityHelpers/Category//Entity[EntityID = $CategoryID]">
<xsl:value-of select="ancestor::*/EntityID"/>
</xsl:for-each>
</xsl:param>
<xsl:param name="ParentID">
<xsl:for-each select="/root/EntityHelpers/Category//Entity[EntityID = $CategoryID]">
<xsl:value-of select="parent::*/EntityID"/>
</xsl:for-each>
</xsl:param>
<xsl:template match="/">
<xsl:element name="ul">
<xsl:attribute name="class">
<![CDATA[menuul]]>
</xsl:attribute>
<xsl:apply-templates select="/root/EntityHelpers/Category/Entity">
<xsl:with-param name="prefix" select="''"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="Entity">
<xsl:param name="prefix"></xsl:param>
<xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" />
<xsl:choose>
<xsl:when test="Published=1">
<li class="menuli">
<xsl:value-of select="$prefix" />
<!--<xsl:if test="number(ParentEntityID) != 0">
<span class="catMark">>></span>�
</xsl:if>-->
<a href="{concat('c-',EntityID,'-',SEName,'.aspx')}">
<xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID">
<xsl:attribute name="class">MenuSelected</xsl:attribute>
</xsl:if>
<xsl:value-of select="$eName" disable-output-escaping="yes"/>
</a>
<xsl:if test="count(child::Entity)>0">
<ul class="submenuul">
<xsl:apply-templates select="Entity">
<xsl:with-param name="prefix" select="concat($prefix, '��')"/>
</xsl:apply-templates>
</ul>
</xsl:if>
</li>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</PackageTransform>
</package>
If you are using ASP.NET you can use standard ASP.NET XML Control.
On page load assign to it your xml and xsl files like below:
protected void Page_Load(object sender, EventArgs e)
{
Xml1.DocumentSource = "~/App_Data/YourXmlFile.xml";
Xml1.TransformSource = "~/App_Data/YourXslStyleSheetFile.xsl";
}
You can also use DocumentContent property your xml is stored not in files but, i.e. in database.
See example here
The accepted answer is true to ASP.Net, but not to Aspdotnetstorefront. The XML file referenced in the question is only generated if debug is enabled and it should not be generated on any production environments (you will end up with write conflicts).
The XML behind the XSLT is generated for you at runtime. The category data (and other entity data) is included because you have includeentityhelper="true". EntityHelper caches category (and other entity) data to reduce DB queries. If you need data in addition to this, you should use the XMLPackage <query> node documented here (under 'SQL Queries'):
http://manual.aspdotnetstorefront.com/p-157-xml-packages.aspx
You'll also find the '' node used in most of the XMLPackages included in the default build.
Related
I am new to xslt and hoping to get answer for this.
I have a xslt file and use it to write a csv.
First time writing to csv, i would like to have a header.
But when I append for next content of csv, I would like to remove the header.
Below is the current xsl.
How do I make the xsl template to be optional to display?
<xsl:template name="Header" match="/">
<xsl:text>Id,Barcode,Name</xsl:text>
<xsl:apply-templates select="abc:Info/Panel" />
</xsl:template>
<xsl:template name="Panel" match="abc:Info/Panel">
<xsl:for-each select="Board/Component">
<xsl:value-of select="../../../../../#Id"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="../../../../../#Barcode"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="../../../../../#Name"/>
<xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:template>
Add a xsl:param to the xslt like i.e. this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:abc="some-namespace"
version="1.0"
>
<xsl:param name="writeHeader" select="'0'"/>
<xsl:template match="/">
<xsl:if test="$writeHeader='1'">
<xsl:text>Id,Barcode,Name</xsl:text>
</xsl:if>
<xsl:apply-templates select="abc:Info/Panel" />
</xsl:template>
<xsl:template match="abc:Info/Panel">
<xsl:for-each select="Board/Component">
<xsl:value-of select="../../../../../#Id"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="../../../../../#Barcode"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="../../../../../#Name"/>
<xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
And if you want to write the header, call your xsl-transformation with the param: writeHeader=1
I have XML file need to convert into HTML using XSLT Code
Please Refer XML File :
<?xml version="1.0" encoding="UTF-8"?><Lesson><Title>Merged Words_G1L5</Title><IntroBlock><ParaBlock><RichText>Materials: Exercise books and pencils</RichText></ParaBlock></IntroBlock><Topic><Title>Underlines – 15 minutes</Title><ParaBlock><CustomNote><SimpleBlock><RichText>
<Underline>ACHIEVE</Underline>
Fill in the Blank: go, wear, quiet, bus, I
1. the pupils are _____.
2. My parents are _____.
3. This school is a _____.
4. ____ am very tall.
5. They _____ sandals.</RichText></SimpleBlock></CustomNote></ParaBlock></Topic></Lesson>
Normally line feed(
) is converted into <br/> tag from my existing code
Existing Code :
1. When Check Line Feed and replace with <br/> tag:
<xsl:template match="text()">
<xsl:param name="text" select="."/>
<xsl:variable name="starttext" select="substring-before(concat($text,'
'),'
')" />
<xsl:variable name="nexttext" select="substring-after($text,'
')"/>
<xsl:if test="normalize-space($starttext)">
<xsl:value-of select="$starttext"/>
<xsl:if test="normalize-space($nexttext)">
<br />
</xsl:if>
</xsl:if>
<xsl:if test="contains($text,'
')">
<xsl:apply-templates select=".">
<xsl:with-param name="text" select="$nexttext"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
Existing Code: 2. Related To Underline:
<xsl:template match="Underline">
<xsl:if test="text() or *">
<u>
<xsl:apply-templates/>
</u>
</xsl:if>
</xsl:template>
Existing Code : 3. Related To Rich Text:
<xsl:template match="RichText">
<xsl:if test="text() or *">
<p>
<xsl:apply-templates/>
</p>
</xsl:if>
</xsl:template>
The above mention is my existing code.
I need a solution for How to check Line Feed(
) when is come after </Underline> tag and </UnderLine> Tag under the <RichText>, Because normal scenario is my code working fine, but is causing only when </UnderLine> tag come under the <RichText>
anyone, please suggest how to I Check Line Feed(
) after </UnderLine> tag in my Code
?????.
Current Issue:
Current Issue
Required Output:
Required Output
You are outputting a <br /> under the condition of:
<xsl:if test="normalize-space($starttext)">
This condition is not true when the text starts with a line-feed - as it does in your example. If you want to preserve the opening line-feed, remove the condition.
What xsl do I need to use myVar1 variable inside myVar2? I'm using an xsl transform to produce the new stylesheet.
<xsl:element name="variable"><xsl:attribute name="myVar1">test value</xsl:attribute> </xsl:element>
<xsl:element name="variable">
<xsl:attribute name="myVar2" />
<xsl:element name="xsl:value-of">
<xsl:attribute name="select">
/root/child[#myattr1='$myVar1']/#value <!--Help here-->
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
I think you mean
<xsl:attribute name="select">
<xsl:value-of select="concat('/root/child[#myattr1=',$myVar1,']/#value')"/>
</xsl:attribute>
How do I convert Richtext images from a standard WPF RichTextBox into HTML using XSLT?
Based on this answer, I have made the following XSLT file. So far, it converts Bold, Italic, Underlined, font family, font size, and font color. Now I still need it to convert images in the Richtext to HTML.
Image alignment does not have to be considered.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl x">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="x:Section[not(parent::x:Section)]">
<div>
<xsl:apply-templates select="node()"/>
</div>
</xsl:template>
<xsl:template match="x:Section">
<xsl:apply-templates select="node()"/>
</xsl:template>
<xsl:template match="x:Paragraph">
<p>
<xsl:apply-templates select="node()"/>
</p>
</xsl:template>
<xsl:template match="x:Run">
<xsl:variable name="style">
<xsl:if test="#FontStyle='Italic'">
<xsl:text>font-style:italic;</xsl:text>
</xsl:if>
<xsl:if test="#FontWeight='Bold'">
<xsl:text>font-weight:bold;</xsl:text>
</xsl:if>
<xsl:if test="contains(#TextDecorations, 'Underline')">
<xsl:text>text-decoration:underline;</xsl:text>
</xsl:if>
<xsl:if test="#FontSize != ''">
<xsl:text>font-size:</xsl:text>
<xsl:value-of select="#FontSize" />
<xsl:text>pt;</xsl:text>
</xsl:if>
<xsl:if test="#FontFamily != ''">
<xsl:text>font-family:</xsl:text>
<xsl:value-of select="#FontFamily" />
<xsl:text>;</xsl:text>
</xsl:if>
<xsl:if test="#Foreground != ''">
<xsl:text>color:#</xsl:text>
<xsl:value-of select="substring(#Foreground, 4)"/>
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:variable>
<span>
<xsl:if test="normalize-space($style) != ''">
<xsl:attribute name="style">
<xsl:value-of select="normalize-space($style)"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="text()"/>
</span>
</xsl:template>
</xsl:stylesheet>
You could add this template - include it above the final </xsl:stylesheet>
<xsl:template match="x:Image">
<img src="#Source" />
</xsl:template>
I have an XML like this:
<table name="tblcats">
<row>
<Id>1741</Id>
<Industry>Oil & Gas - Integrated</Industry>
<ParentId>1691</ParentId>
</row>
<row>
<Id>1690</Id>
<Industry>Commodities</Industry>
<ParentId>1691</ParentId>
</row>
<row>
<Id>1691</Id>
<Industry>Capital Goods</Industry>
<ParentId>0</ParentId>
</row>
</table>
I want to create a Treeview from this XML so that table is parent node and then nodes ParentId 0 is second parent and then child nodes with Parent Id greater than 0
Like this:
+Table
+Capital Goods
Commodities
Oil & Gas - Integrated
How can I do this? Please suggest
Regards,
Asif Hameed
A fairly simplistic approach would be to use the standard ASP.NET controls XmlDataSource and TreeView and use an XSLT transform file to transform the XML you have into something that the TreeView control likes.
So, assuming you have the XML above in a file called cats.xml, the ASP.NET page markup would look like:
<asp:XmlDataSource ID="CatsXml" runat="server" DataFile="~/cats.xml" TransformFile="~/cats.xslt"></asp:XmlDataSource>
<asp:TreeView ID="CatsTree" runat="server" DataSourceID="CatsXml">
<DataBindings><asp:TreeNodeBinding TextField="name" ValueField="id" /></DataBindings>
</asp:TreeView>
and the XSLT file (cats.xslt) would be:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="table">
<table id="-1" name="Table">
<xsl:for-each select="/table/row[ParentId = 0]">
<industry>
<xsl:attribute name="id">
<xsl:value-of select="Id"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="Industry"/>
</xsl:attribute>
<xsl:call-template name="industry-template">
<xsl:with-param name="pId" select="Id" />
</xsl:call-template>
</industry>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="industry-template">
<xsl:param name="pId" />
<xsl:for-each select="/table/row[ParentId = $pId]">
<industry>
<xsl:attribute name="id">
<xsl:value-of select="Id"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="Industry"/>
</xsl:attribute>
<xsl:call-template name="industry-template">
<xsl:with-param name="pId" select="Id" />
</xsl:call-template>
</industry>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Stuart.