簡體   English   中英

將數據從xml doc插入xsl

[英]Inserting data from the xml doc to the xsl

我是使用XSL和XML的初學者。 我從XML文檔中獲取數據並在XSL中使用它時遇到問題。 目前我正在嘗試不同的方法,但似乎無法做到正確,我將需要使用這種技術來完成項目。 一旦我能夠完成一個,我將能夠在整個頁面中完成。

以下是我的XML和我的XSL文檔中的示例:

<storelocator> 
    <!--Parent element containing all text on the page-->
    <content_text> 
        <title>
            <titlename>Store Locator</titlename> 
        </title>
        <title>
            <subtitle>FIND A STORE</subtitle>
        </title>
        <title>
            <countrydropdown>Country</countrydropdown>
        </title>
        <title>
            <address>Steet Address, City, Sate/Province OR Postal/Zip Code</address>
        </title>
        <title>
            <radiusdropdown>Radius</radiusdropdown>
        </title>
        <title>
            <featuredstore>FEATURED STORE</featuredstore>
        </title>
        <title>
            <storelocation>Newbury Street, Boston, MA USA</storelocation>
        </title>
</storelocator>

這是XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body bgcolor="white">

<div id="container" style="100%">

<div id="header" style="background: url('header.png'); height:30px;"></div>

<div id="content_container" align="center" style="text-transform: uppercase; font-family: tahoma; font-weight: normal; font-size: 0.8em">
    <div id="content" align="left" style="background-color:blue;height:845px;width:848px">

   <xsl:value-of select="titlename"/> <!--here I was trying to import the text from XML DOC-->

<br/>
<br/>
<br/>
    <img src="image.png" align="left"/><br/>
<br/>
<br/>
<br/>
<br/>

</div>
</div>

<div id="footer" style="background-color:black;clear:both;text-align:center;height:20px"></div>
</div>
</body>
</html>

</xsl:template>
</xsl:stylesheet>

基本上我要做的是導入“商店定位器”標題,使其顯示在圖像上方但當前在瀏覽器中打開時沒有任何內容。 我非常感謝一些幫助,因為我一直試圖這樣做。

在XSLT中要記住的最重要的事情之一是所有路徑都將基於上下文。 在您的示例中,上下文是/因為在您的模板中,您匹配/ 你不能直接從/titlename

嘗試將xsl:value-of更改為:

<xsl:value-of select="storelocator/content_text/title/titlename"/>

此外,XSLT不是“導入”您的XML; 它正在改變它。 如果你只是在瀏覽器中打開XSLT,這是行不通的。 要在打開XML時使轉換在瀏覽器中工作,您必須添加指向XSLT的處理指令:

<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<storelocator> 
...
</storelocator>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM