2013-02-02 4 views
-1

XML 데이터를 사용하는 XSLT 시트를 처리하는 데 C#을 사용하고 있습니다.XSLT 파일에 XML 데이터가 표시되지 않습니다.

내 XSLT 시트에서 XML 데이터를 통과하는 템플릿을 적용하고 전달 된 매개 변수를 기반으로 수치를 버리는 것으로 가정합니다.

XSLT 시트를 실행하고 매개 변수를 전달할 때 출력이 없습니다. XSLT의 html 측면이 정상적으로 작동하는 것 같습니다.

http://pastebin.com/B3eqbd6K

나는 우리가 내 C#을 제외하면, 위의를 처리하기 위해 비주얼 스튜디오 2012을 사용하고 있습니다 : 여기

http://pastebin.com/eL9wnRgK

내 XML 파일입니다 : 여기

내 XSLT 코드 내가 xslt를 처리하는 데 사용하는 클래스, 심지어 내장 된 XSLT 디버거에서 VS (아무 데이터도 출력되지 않는 것)가없는 것처럼 보입니다.

시간이 많이 걸렸지 만 어디서 잘못되었는지 알 수없고 빨간색으로 강조 표시된 구문이나 표시된 오류가 없습니다. 이 언어는 C#보다 훨씬 어렵습니다. ...

+0

매개 변수를 어떻게 제공합니까? – rene

+1

누구나 250 줄의 XSLT를 디버깅 할 것으로 기대할 수는 없습니다. 문제를 해결하고 20 행의 코드 샘플을 게시하십시오. – Tomalak

+0

사용중인 C# 코드를 게시 할 수 있습니까? 특히 매개 변수를 설정하는 방법을 보여줄 수 있습니까? 감사! –

답변

1

XSLT는 심각한 정리가 필요했습니다. DRY principle을 기억하십시오. 반복 된 부분을 사용하지 않으므로 XSLT의 길이를 100 줄 이상 줄일 수있었습니다. 올바르게 매개 변수 값을 전달하는 방법을 파악하면이 작동합니다 :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <!--Search parameter to store the search string entered--> 
    <xsl:param name="SearchRecipe" /> 
    <!--Search type parameter to store the type of search selected--> 
    <xsl:param name="SearchType" select="'Start'" /> 
    <xsl:param name ="IsVegetarian" /> 

    <!--First part of code to capture values from user and then store them 
     in the variables above--> 
    <xsl:template match="/"> 
    <html> 

     <head> 
     <!--Sets Title of Page (within our Master template)--> 
     <a> 
      <title>Recipe Headquarters</title> 
     </a> 
     <!--Reference to the stylesheet we are using--> 
     <link href="Cafesheet.css" rel="stylesheet" type="text/css" /> 
     </head> 

     <body> 
     <form id="banner" name="content" method="get" action="Commercial.aspx"> 
      <h1 >Recipe Book</h1> 
      <div id="content"> 
      <p> 
       <label id="h2" for="txtFilter">Search Recipe Book </label> 

       <input type="text" name="txtFilter" 
        id="txtFilter" value="{$SearchRecipe}"/> 

       <!--Creates a simple submit button--> 
       <input type="submit" name="btnSearch" 
        id="btnSearch" value="Submit" /> 
       <br /> 
       <br /> 


       <!--Label of text for our set of radio buttons--> 
       <label for="rdoSearchType">Select a Search Type </label> 

       <!--Behold, the radio buttons themselves--> 
       <xsl:call-template name="SearchTypeRadio"> 
       <xsl:with-param name="value" select="'Start'" /> 
       <xsl:with-param name="text" select="'Starts with'" /> 
       </xsl:call-template> 
       <xsl:call-template name="SearchTypeRadio"> 
       <xsl:with-param name="value" select="'Contains'" /> 
       <xsl:with-param name="text" select="'Contains'" /> 
       </xsl:call-template> 
       <xsl:call-template name="SearchTypeRadio"> 
       <xsl:with-param name="value" select="'RecipeType'" /> 
       <xsl:with-param name="text" select="'Recipe Type'" /> 
       </xsl:call-template> 
       <br /> 
       <br /> 
       <br /> 

       <!--Applys the template from the second part--> 
       <xsl:apply-templates 
       select="CafeRecipes[$SearchType = 'Start' or 
            $SearchType = 'Contains' or 
            $SearchType = 'RecipeType']" /> 

      </p> 
      <!--End our of Search input text box and the Type of search 
        we want to do Div--> 
      </div> 

      <!--Our self closing footer div, yayyyy. Single line madness--> 
      <h1>Made by Jagga ^_^</h1> 
     </form> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template name="SearchTypeRadio"> 
    <xsl:param name="value" /> 
    <xsl:param name="text" /> 
    <input type="radio" name="rdoSearchType" value="{$value}"> 
     <xsl:if test="$SearchType = $value"> 
     <xsl:attribute name="checked">checked</xsl:attribute> 
     </xsl:if> 
     <xsl:value-of select="$text"/> 
    </input> 
    </xsl:template> 

    <!--This will be the second part of the xsl code to manipulate the data 
      based on our chosen values from above--> 
    <!--Declares new xsl template--> 
    <xsl:template match="CafeRecipes"> 
    <!--Creates a small table to display the data output produced--> 
    <table id="content" border="5"> 
     <tr> 
     <th>Recipe #</th> 
     <th>Recipe Name</th> 
     <th>Ingredients Required</th> 
     <th>Instructions</th> 
     <th>Recipe Type</th> 
     <th>Vegetarian?</th> 
     </tr> 

     <xsl:variable name="matchedRecipes" 
     select="ARecipe[ 
       ($SearchType = 'Start' and starts-with(ItemName, $SearchRecipe)) or 
       ($SearchType = 'Contains' and contains(ItemName, $SearchRecipe)) or 
       ($SearchType = 'RecipeType' and 
          contains(RecipeInfo/RecipeType, $SearchRecipe)) 
          ]" /> 

     <xsl:if test="$SearchType = 'Start' or $SearchType = 'Contains'"> 
     <xsl:apply-templates select="$matchedRecipes"> 
      <xsl:sort select="RecipeInfo/RecipeType" order="ascending" /> 
     </xsl:apply-templates> 
     </xsl:if> 
     <xsl:if test="$SearchType = 'RecipeType'"> 
     <xsl:apply-templates select="$matchedRecipes"> 
      <xsl:sort select="ItemName" order="ascending" /> 
     </xsl:apply-templates> 
     </xsl:if> 
    </table> 
    </xsl:template> 

    <xsl:template match="ARecipe"> 
    <tr> 
     <xsl:apply-templates select="*[not(*)] | RecipeInfo/*" /> 
    </tr> 
    </xsl:template> 

    <xsl:template match="ARecipe/* | ARecipe/*/*"> 
    <td width="300"> 
     <xsl:apply-templates select="." mode="content" /> 
    </td> 
    </xsl:template> 

    <xsl:template match="Vegetarian[. = 'Yes']" mode="content"> 
     YesThisWorks and it's vegetarian 
    </xsl:template> 

    <xsl:template match="Vegetarian[. = 'No']" mode="content"> 
    YesThisWorks and it's NOT vegetarian 
    </xsl:template> 
</xsl:stylesheet> 

당신의 ASPX 코드에서 내가 볼 AddParameter()의 유일한 호출 MyXMLConduit.AddParameter("TheFilter", AFilter);입니다. XSLT에서 매개 변수의 이름이 "SearchRecipe"이므로 "TheFilter"가 아닌 매개 변수 이름으로 사용해야합니다. 또한 rdoSearchType 쿼리 매개 변수의 값을 가져와 XSLT 매개 변수 중 하나로 추가해야합니다.

string searchType = Request["rdoSearchType"]; 
if(searchType != null) 
{ 
    MyXMLConduit.AddParameter("SearchType", searchType); 
} 
+0

안녕하세요. @JLRishe : 답변 해 주시고 코드를 정렬 해 주셔서 감사합니다. 나는 XSLT에 대해 혼란스러워하고 있으며 아직 단축 된 코드를 적용하지 않았다. 나는 definetly 그러나 순간에 나는 단지 통과 할 값을 얻으려고 노력하고있을거야 내 C#에서 xslt. 지금까지 내 XSLT는 다음과 같이 보입니다 : [http://pastebin.com/NvnPFy0b] .... 위에서 제시 한대로 하드 코드 값을 사용할 수 있지만 실제로 수행해야 할 작업은 C# 클래스의 값을 전달하는 것입니다. xslt 시트에 넣습니다. – JARRRRG

+0

@Jagga 감사합니다. 내 대답에 C# 코드에 대한 몇 가지 제안을 추가했습니다. – JLRishe

+0

필자가 지금 보았던 이유는 매개 변수 (그냥 1을 추가했습니다)가 단순히 xslt에 전달한 이름이고 xslt에서 사용하지 않았기 때문에 실패했기 때문입니다. 네가 물었을 때 나는 그랬고 지금은 예상대로 일하고있다. 나는 V에 넣었고, V로 그것과 함께 조리법의 모든 이름을 보여줍니다. 이제는 잘 작동합니다. 나는 이제 잠 잘 수있을 것이라고 생각합니다. P, 대단히 감사합니다. @ JLRishe와 다른 사람들은 그들의 의견을 들어주었습니다! – JARRRRG

관련 문제