2010-02-27 17 views
1

我有一個用於xml的xsl文件。 xml文件的位置應該是可配置的(這是通過在xml中配置樣式表的href路徑來完成的),但是xsl使用了一些圖像和其他一些javaScript文件,並且需要具有它們的路徑。路徑就在樣式表文件的附近,所以一旦我可以得到xsl目錄,我就可以向他們發送消息。 例如: 在我的xml中我有:?xml-stylesheet type =「text/xsl」href =「。\ Files \ Style \ test.xsl」> 我想從xsl內指向「。\ Files \樣式」爲圖像位置 耕犁我可以做到這一點從XSL文件中獲取樣式表目錄 - 用於可配置的xml位置

+0

看到解決您的問題:) – 2010-03-01 14:39:54

+0

提示問題左上角的複選標記。根據您目前獲得的積分,您也可以升級它(我認爲您必須擁有50分,才能享有優惠權)。 :) – 2010-03-04 13:30:56

+0

謝謝, 我仍然需要你的幫助:) 我有一個xsl trnafering到我的xsl中的一個html我有幾個模板和一些java腳本函數什麼是正確的方式來傳遞信息到其他模板和jScript - 如果我在模板匹配的場景中有問題嗎?因爲我沒有辦法走上這條路。這可能是一個初學者的問題,但我在這方面很新。我很感謝你的幫助 – user271077 2010-03-07 19:10:09

回答

1

下面是一個XSLT 1.0溶液(XSLT 2.0具有用於字符串處理更強大的功能,如正則表達式):

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

<xsl:template match="processing-instruction()"> 
    <xsl:variable name="vpostHref" 
    select="substring-after(., 'href=')"/> 

    <xsl:variable name="vhrefData1" 
    select="substring($vpostHref,2)"/> 

    <xsl:variable name="vhrefData2" 
    select="substring($vhrefData1, 1, 
         string-length($vhrefData1)-1 
        )"/> 

    <xsl:call-template name="stripBackwards"> 
    <xsl:with-param name="pText" 
     select="$vhrefData2"/> 
    <xsl:with-param name="pTextLength" 
    select="string-length($vhrefData2)"/> 
    </xsl:call-template> 
</xsl:template> 

<xsl:template name="stripBackwards"> 
    <xsl:param name="pText"/> 
    <xsl:param name="pStopChar" select="'\'"/> 
    <xsl:param name="pTextLength"/> 

    <xsl:choose> 
    <xsl:when test="not(contains($pText, $pStopChar))"> 
    <xsl:value-of select="$pText"/> 
    </xsl:when> 
    <xsl:otherwise> 
    <xsl:variable name="vLastChar" 
     select="substring($pText,$pTextLength,1)"/> 
    <xsl:choose> 
     <xsl:when test="$vLastChar = $pStopChar"> 
     <xsl:value-of select="substring($pText,1,$pTextLength -1)"/> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:call-template name="stripBackwards"> 
      <xsl:with-param name="pText" 
      select="substring($pText,1,$pTextLength -1)"/> 
      <xsl:with-param name="pTextLength" select="$pTextLength -1"/> 
      <xsl:with-param name="pStopChar" select="$pStopChar"/> 
     </xsl:call-template> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
</xsl:stylesheet> 

將此轉換應用於以下XML文檔時:

<?xml-stylesheet type="text/xsl" href=".\Files\Style\test.xsl"?> 
<t/> 

正確的結果產生:通過單擊如果提供的答案解決了這個問題,你可以接受* *它:

.\Files\Style 
+0

謝謝!!! 看起來正是我想要的,我會試試看 – user271077 2010-03-04 06:19:50