2011-12-19 50 views
0

質問を実行するASPDOTNETSTOREFRONTのxmlパッケージを作成しました。その後、ファイルは製品リンクを作成するULを作成します。しかし、私はカテゴリーとその中に表示される製品のリンクのために表示する別のULが必要です。XMLパッケージ内で製品カテゴリULを作成しますか?

<ul>Category 1</ul> 
<ul> 
    <li>product 1</li> 
</ul> 
</ul> 

上記のようなものはありますか?ここで

は私のxmlパッケージです:

<?xml version="1.0" standalone="yes" ?> 
<package version="2.1" displayname="Simple Product" debug="true" includeentityhelper="false"> 

    <!-- ###################################################################################################### --> 
    <!-- Copyright AspDotNetStorefront.com, 1995-2011. 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.                 --> 
    <!--                          --> 
    <!-- ###################################################################################################### --> 

    <query name="Products" rowElementName="Product"> 
     <sql> 
      <![CDATA[ 
       WITH Categories (ParentCategoryID, CategoryID, Name, ComputedLevel, Sort) AS 
        (
        SELECT c.ParentCategoryID, c.CategoryID, c.Name, 0 AS ComputedLevel, CAST('\'+c.Name AS NVARCHAR(255)) 
        FROM Category AS c 
        WHERE ParentCategoryID = 0 
        AND Deleted=0 
        AND Published=1 
        UNION ALL 
        SELECT c.ParentCategoryID, c.CategoryID, c.Name, ComputedLevel + 1, CAST(s.Sort + '\'+c.Name AS NVARCHAR(255)) 
        FROM Category AS c 
        INNER JOIN Categories AS s ON c.ParentCategoryID = s.CategoryID 
        WHERE Deleted=0 
        AND Published=1 
        ) 

        SELECT ParentCategoryID, c.CategoryID, Sort, p.ProductID, p.Name, p.SEName 
        FROM Categories c (NOLOCK) 
        LEFT JOIN ProductCategory pc (NOLOCK) ON pc.CategoryID = c.CategoryID 
        JOIN Product p (NOLOCK) ON p.ProductID = pc.ProductID 

        ORDER BY 3,5 
      ]]> 
     </sql> 

    </query> 

    <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="LocaleSetting" select="/root/Runtime/LocaleSetting" /> 
      <xsl:param name="WebConfigLocaleSetting" select="/root/Runtime/WebConfigLocaleSetting" /> 
      <xsl:param name="XmlPackageName" select="/root/System/XmlPackageName" /> 
      <xsl:param name="SecID"> 
       <xsl:choose> 
        <xsl:when test="count(/root/QueryString/sectionid) &gt; 0"> 
         <xsl:value-of select="/root/QueryString/sectionid" /> 
        </xsl:when> 
        <xsl:otherwise>0</xsl:otherwise> 
       </xsl:choose> 
      </xsl:param> 

      <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:param name="CatID"> 
       <xsl:choose> 
        <xsl:when test="count(/root/QueryString/categoryid) &gt; 0"> 
         <xsl:value-of select="/root/QueryString/categoryid" /> 
        </xsl:when> 
        <xsl:otherwise>0</xsl:otherwise> 
       </xsl:choose> 
      </xsl:param> 


      <xsl:template match="/"> 
       <xsl:element name="ul"> 
        <xsl:attribute name="id"> 
         <![CDATA[accordion3]]> 
        </xsl:attribute> 
        <xsl:apply-templates select="/root/Products/Product"> 
         <xsl:with-param name="prefix" select="''"/> 
        </xsl:apply-templates> 
       </xsl:element> 
      </xsl:template> 



      <xsl:template match="Product"> 
       <xsl:param name="prefix"></xsl:param> 
       <xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" /> 
       <li > 
        <!--<xsl:value-of select="$prefix" />--> 
        <xsl:if test="number(ParentEntityID) != 0"> 
         <!--<span class="catMark">&gt;&gt;</span>&#160;--> 




         <a href="{concat('p-',ProductID,'-',SEName,'.aspx')}"> 
          <xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID"> 
           <xsl:attribute name="style">font-weight:bold</xsl:attribute> 
          </xsl:if> 
          <xsl:value-of select="$eName"/> 
         </a> 



        </xsl:if> 
        <xsl:if test="number(ParentEntityID) = 0"> 
         <div class="menuText"> 
          <xsl:value-of select="$eName"/> 
         </div> 
        </xsl:if> 
        <xsl:if test="count(child::Entity)&gt;0"> 
         <ul > 
          <xsl:apply-templates select="Product"> 
           <xsl:with-param name="prefix" select="concat($prefix, '&#160;&#0160;')"/> 
          </xsl:apply-templates> 
         </ul> 
        </xsl:if> 
       </li> 
      </xsl:template> 


     </xsl:stylesheet> 
    </PackageTransform> 
</package> 

ULは、ここで作成された:製品のリンクが作成される場所

<xsl:template match="/"> 
       <xsl:element name="ul"> 
        <xsl:attribute name="id"> 
         <![CDATA[accordion3]]> 
        </xsl:attribute> 
        <xsl:apply-templates select="/root/Products/Product"> 
         <xsl:with-param name="prefix" select="''"/> 
        </xsl:apply-templates> 
       </xsl:element> 
      </xsl:template> 

そして、ここでは、次のとおりです。

<xsl:template match="Product"> 
     <xsl:param name="prefix"></xsl:param> 
     <xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" /> 
     <li > 
      <!--<xsl:value-of select="$prefix" />--> 
      <xsl:if test="number(ParentEntityID) != 0"> 
       <!--<span class="catMark">&gt;&gt;</span>&#160;--> 

       <a href="{concat('p-',ProductID,'-',SEName,'.aspx')}"> 
        <xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID"> 
         <xsl:attribute name="style">font-weight:bold</xsl:attribute> 
        </xsl:if> 
        <xsl:value-of select="$eName"/> 
       </a> 


      </xsl:if> 
      <xsl:if test="number(ParentEntityID) = 0"> 
       <div class="menuText"> 
        <xsl:value-of select="$eName"/> 
       </div> 
      </xsl:if> 
      <xsl:if test="count(child::Entity)&gt;0"> 
       <ul > 
        <xsl:apply-templates select="Product"> 
         <xsl:with-param name="prefix" select="concat($prefix, '&#160;&#0160;')"/> 
        </xsl:apply-templates> 
       </ul> 
      </xsl:if> 
     </li> 
    </xsl:template> 

EDIT:追加しますXML抽出:

<Product> 
    <ParentCategoryID>77</ParentCategoryID> 
    <CategoryID>78</CategoryID> 
    <Sort>\Box Product\Accessories\AA990F</Sort> 
    <ProductID>299</ProductID> 
    <Name>Air compressor</Name> 
    <SEName>air-compressor</SEName> 
</Product> 
+1

あなたは、また、完全な(しかしほどの小さなを提供してもらえ可能な)XSLT変換の入力となるXML文書ですか? –

+0

はページの最後に編集を追加しました。それはXMLの抽出を示しています.. – PD24

+0

また、私はこのようなフライアウトメニューを作成することができないので、間違っている各liに各製品のリンクを追加するようだ。私はそれぞれのカテゴリが独自のUL/Liを持っている必要があります...私が意味するワットを知っていますか? – PD24

答えて

0

今後この問題に直面する可能性があるので、この回答を投稿しています。 このコードを使用して、製品を提供してください。

例:

  • カテゴリー1

    .Product 1 
    
    .product 2 
    
  • カテゴリー2

    .Product 1 
    .Product 2 
    
    
    
    
    <?xml version="1.0" standalone="yes" ?> 
    <package version="2.1" displayname="Simple Product" debug="false" 
    includeentityhelper="false"> 
    <query name="Products" rowElementName="Product"> 
    <sql> 
        <![CDATA[ 
          WITH Categories (ParentCategoryID, CategoryID, Name, 
         ComputedLevel, Sort) AS 
           (
           SELECT c.ParentCategoryID, c.CategoryID, c.Name, 0 AS 
            ComputedLevel, CAST('\'+c.Name AS NVARCHAR(255)) 
           FROM Category AS c 
           WHERE ParentCategoryID [email protected] 
           AND Deleted=0 
           AND Published=1 
           UNION ALL 
           SELECT c.ParentCategoryID, c.CategoryID, c.Name, 
           ComputedLevel + 1, CAST(s.Sort + '\'+c.Name AS 
           NVARCHAR(255)) 
           FROM Category AS c 
           INNER JOIN Categories AS s ON c.ParentCategoryID = 
           s.CategoryID 
           WHERE Deleted=0 
           AND Published=1 
           ) 
    
           SELECT ParentCategoryID, c.CategoryID,C.Name as 
           CategoryName, Sort, p.ProductID, p.Name, p.SEName 
           FROM Categories c (NOLOCK) 
           LEFT JOIN ProductCategory pc (NOLOCK) ON pc.CategoryID = 
           c.CategoryID 
           JOIN Product p (NOLOCK) ON p.ProductID = pc.ProductID 
    
           ORDER BY 3,5 
            ]]> 
            </sql> 
           <queryparam paramname="@CatID"   
            paramtype="runtime" requestparamname="CatID"          
    
    sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@SecID"   paramtype="runtime" requestparamname="SecID"           sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@ManID"   paramtype="runtime" requestparamname="ManID"           sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@DistID"   paramtype="runtime" requestparamname="DistID"          sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@GenreID"  paramtype="runtime" requestparamname="GenreID"          sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@VectorID"  paramtype="runtime" requestparamname="VectorID"          sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@locale"   paramtype="runtime" requestparamname="LocaleSetting"         sqlDataType="varchar" defvalue="en-US" validationpattern="" /> 
        <queryparam paramname="@CustLevelID" paramtype="runtime" requestparamname="CustomerLevelID"        sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@AffID"   paramtype="runtime" requestparamname="AffiliateID"         sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@ProdTypeID"  paramtype="runtime" requestparamname="ProductTypeFilterID"       sqlDataType="int"  defvalue="1"  validationpattern="" /> 
        <queryparam paramname="@pgnum"   paramtype="request" requestparamname="pagenum"          sqlDataType="int"  defvalue="1"  validationpattern="" /> 
        <queryparam paramname="@InvFilter"  paramtype="appconfig" requestparamname="HideProductsWithLessThanThisInventoryLevel" sqlDataType="int"  defvalue="0"  validationpattern="" /> 
        <queryparam paramname="@entityname"  paramtype="runtime" requestparamname="EntityName"         sqlDataType="varchar" defvalue=""  validationpattern="" /> 
        <queryparam paramname="@StoreID"  paramtype="runtime" requestparamname="StoreID"               sqlDataType="int"  defvalue="1"  validationpattern="" /> 
        <queryparam paramname="@FilterProduct" paramtype="runtime" requestparamname="FilterProduct"             sqlDataType="bit"  defvalue="0"  validationpattern="" /> 
        </query> 
    
        <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="LocaleSetting" select="/root/Runtime/LocaleSetting" /> 
         <xsl:param name="WebConfigLocaleSetting" select="/root/Runtime/WebConfigLocaleSetting" /> 
         <xsl:param name="XmlPackageName" select="/root/System/XmlPackageName" /> 
         <xsl:param name="SecID"> 
    
         <xsl:variable name="ShowSubcatsInGrid" select="aspdnsf:AppConfig('ShowSubcatsInGrid')" /> 
         <xsl:variable name="EntityName" select="/root/Runtime/EntityName" /> 
         <xsl:variable name="EntityID" select="/root/Runtime/EntityID" /> 
    
    
         <xsl:variable name="CurrentEntity" select="/root/EntityHelpers/*[name()=$EntityName]/descendant::Entity[EntityID=$EntityID]" /> 
    
         <xsl:choose> 
          <xsl:when test="count(/root/QueryString/sectionid) &gt; 0"> 
          <xsl:value-of select="/root/QueryString/sectionid" /> 
          </xsl:when> 
          <xsl:otherwise>0</xsl:otherwise> 
         </xsl:choose> 
         </xsl:param> 
    
         <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:param name="CatID"> 
    
         <xsl:choose> 
          <xsl:when test="count(/root/QueryString/categoryid) &gt; 0"> 
          <xsl:value-of select="/root/QueryString/categoryid" /> 
          </xsl:when> 
          <xsl:otherwise>0</xsl:otherwise> 
         </xsl:choose> 
         </xsl:param> 
    
         <xsl:template match="/"> 
         <xsl:element name="ul"> 
          <xsl:attribute name="id"> 
          <![CDATA[accordion3]]> 
          </xsl:attribute> 
          <xsl:apply-templates select="/root/Products/Product"> 
          <xsl:with-param name="prefix" select="''"/> 
          </xsl:apply-templates> 
         </xsl:element> 
         </xsl:template> 
    
         <xsl:template match="Product"> 
         <xsl:param name="prefix"></xsl:param> 
         <xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" /> 
         <xsl:variable name="oldname" select="'old'" /> 
         <li > 
          <!--<xsl:value-of select="$prefix" />--> 
    
          <xsl:if test="number(ParentEntityID) != 0"> 
          <!--<span class="catMark">&gt;&gt;</span>&#160;--> 
    
          <!--<xsl:if test="$oldname != CategoryName">--> 
          <xsl:if test ="not(preceding-sibling::Product[(CategoryName/text() = current()/CategoryName/text())])"> 
          <h1> 
           <xsl:value-of select="CategoryName"/> 
          </h1>    
           <!--<xsl:variable name="oldname" select="CategoryName" />--> 
           <!--<xsl:copy> 
           <xsl:value-of name="oldname" select="CategoryName"/> 
           </xsl:copy>--> 
    
           </xsl:if> 
    
          <a href="{concat('p-',ProductID,'-',SEName,'.aspx')}"> 
           <xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID">    
           <xsl:attribute name="style">font-weight:bold</xsl:attribute> 
           </xsl:if> 
           <xsl:value-of select="$eName"/> 
          </a> 
    
    
    
          </xsl:if> 
          <xsl:if test="number(ParentEntityID) = 0"> 
          <div class="menuText"> 
           <xsl:value-of select="$eName"/>    
          </div> 
          </xsl:if>  
    
          <xsl:if test="count(child::Product)&gt;0"> 
    
          <ul > 
           <xsl:apply-templates select="Product"> 
           <xsl:with-param name="prefix" select="concat($prefix, '&#160;&#0160;')"/> 
           </xsl:apply-templates> 
          </ul> 
          </xsl:if> 
         </li> 
         </xsl:template> 
    
    
        </xsl:stylesheet> 
        </PackageTransform> 
    </package> 
    
関連する問題