2013-08-20 57 views
1

我的代碼如下所示,它給出了樣式表編譯錯誤。XSL:選擇查詢

<xsl:template match="form"> 
     <xsl:copy> 
      <xsl:for-each select="@*"> 
       <xsl:variable name="param" select="name(.)" /> 
       <xsl:choose> 
        <xsl:when test="$param = 'name'"> 
         <xsl:attribute name="name"><xsl:value-of 
          select="@name" /></xsl:attribute> 
        </xsl:when> 
        <xsl:when test="$param = 'action'"> 
         <xsl:attribute name="action"><xsl:value-of 
          select="java:com.hp.cpp.proxy.util.URLUtils.rewriteAction($response, $baseurl, @action, $scope)" /></xsl:attribute> 
        </xsl:when> 
        <xsl:when test="$param = 'method'"> 
         <xsl:attribute name="method">POST</xsl:attribute> 
        </xsl:when> 
        <xsl:otherwise> 
         <xsl:attribute name="$param"><xsl:value-of 
          select="." /></xsl:attribute> 
        </xsl:otherwise> 
       </xsl:choose> 
      </xsl:for-each> 
      <input type="hidden" name="httpmethod"> 
       <xsl:attribute name="value"> <xsl:value-of 
        select="@method" /></xsl:attribute> 
      </input> 
      <xsl:apply-templates select="node()|@*" /> 

     </xsl:copy> 
    </xsl:template> 

我想重新寫HTML的FORM標籤與相當複雜的要求。希望你能通過代碼捕捉來識別。我正在嘗試重新編寫標籤的一些屬性,並試圖保留其餘部分。這是正確的方式嗎?任何其他方式來做到這一點?任何建議。

在此先感謝。

-Rikin

+1

你說你得到一個編譯錯誤,但沒有哪一個。你也可以將你的問題標記爲1.0和2.0,這是什麼?你能用一個最小的完整例子(包括xsl:stylesheet和聲明的命名空間)更新你的問題嗎?我的猜測是擴展方法'rewriteAction'沒有聲明或不存在。 – Abel

回答

0

只是一個猜測。試圖取代過去的這個

<xsl:apply-templates select="node()" /> 
0

關於編譯錯誤適用

<xsl:apply-templates select="node()|@*" /> 

,你沒有提供足夠的信息,以幫助;阿貝爾猜想,編譯錯誤與你對擴展函數的調用是有道理的。

您還可以問問這是正確的方法嗎?來達到你的目標。也許。你的第一個問題是jvverde已經指出的邏輯錯誤。應用模板的調用不應選擇屬性;你已經處理了所有的屬性。所以再次處理它們是沒有必要的。這也是一個壞主意:如果您嘗試再次處理元素的屬性,則會因運行時錯誤,因爲您已將內容寫入元素(即input元素)。

我想有些XSLT程序員會寫的東西看起來更像是這樣的:

<xsl:template match="form"> 
    <xsl:copy> 

    <!--* don't use a for-each to handle the 
     * attributes; use templates. *--> 
    <xsl:apply-templates select="@*"/> 

    <!--* you don't need an xsl:attribute constructor 
     * if you want to use an expression within a 
     * literal result element; just braces in the 
     * attribute-value template. 
     *--> 
    <input type="hidden" 
      name="httpmethod" 
      value="{@method}" /> 

    <!--* change your apply-templates call to 
     * select children, but not attributes. 
     *--> 
    <xsl:apply-templates select="node()" /> 
    </xsl:copy> 
</xsl:template> 

<!--* now the attributes ... *--> 
<xsl:template match="form/@action"> 
    <xsl:attribute name="action"> 
    <xsl:value-of select="java:com.hp.cpp.proxy.util.URLUtils.rewriteAction(
          $response, $baseurl, @action, $scope)" /> 
    </xsl:attribute> 
</xsl:template> 
<xsl:template match="form/@method"> 
    <xsl:attribute name="method"> 
    <xsl:value-of select="'POST'"/> 
    </xsl:attribute> 
</xsl:template>