简体   繁体   English

通过xsl文件查询数据库

[英]query database via xsl file

I have an ecommerce cart which generates the XML at runtime. 我有一个电子商务购物车,可以在运行时生成XML。 I have access to the XSL stylesheet which styles the actual XML. 我可以访问为实际XML设置样式的XSL样式表。

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? 有没有在xsl文件中运行查询的示例,您可以向我展示?

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 . 如果使用的是ASP.NET,则可以使用标准的ASP.NET XML Control

On page load assign to it your xml and xsl files like below: 在页面加载时,将其xml和xsl文件分配给它,如下所示:

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, ie in database. 您也可以使用DocumentContent属性,将xml而不是存储在文件中,而是存储在数据库中。

See example here 在这里查看示例

The accepted answer is true to ASP.Net, but not to Aspdotnetstorefront. 接受的答案对ASP.Net是正确的,但对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). 问题中引用的XML文件仅在启用了调试的情况下生成,并且不应在任何生产环境中生成(您最终会发生写冲突)。

The XML behind the XSLT is generated for you at runtime. XSLT背后的XML是在运行时为您生成的。 The category data (and other entity data) is included because you have includeentityhelper="true" . 包含类别数据(和其他实体数据)是因为您具有includeentityhelper="true" EntityHelper caches category (and other entity) data to reduce DB queries. EntityHelper缓存类别(和其他实体)数据以减少数据库查询。 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 如果除此之外还需要数据,则应使用此处记录的XMLPackage <query>节点(在“ SQL查询”下): 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. 您还将找到默认构建中包含的大多数XMLPackages中使用的''节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM