开发者

Sourcing multiple xml docs from single xslt

I am tr开发者_Go百科ying this and cannot seem to get it to work. Can someone take a look and see if I am missing something obvious.

I am referencing the extra doc like this in test.xsl.

<xsl:value-of select="document('/customercare/library/test/test1.xml')/resources/resource/name" />

This is the xml test1.xml.

<resources>
    <resource>  
        <name>configuration</name>
    </resource> 
</resources>

This is the fragment call in my asp page index.aspx.

<%
            Dim mm_xsl As MM.XSLTransform = new MM.XSLTransform()
            mm_xsl.setXML(Server.MapPath("/customercare/library/test/test2.xml"))
            mm_xsl.setXSL(Server.MapPath("/customercare/library/test/test.xsl"))            
            Response.write(mm_xsl.Transform())
        %>

I am architecting a site that will have several hundred products. I would like to have one xml doc that contains high level details such as name and image path for every product that can be sourced from everywhere, this would have a unique schema. Then have another xml doc with a unique schema that contains items specific to a sub section such as support that would contain document paths, phone numbers and etc.

My question is how do I source both xml documents from within a single xslt?

Thanks


Have a look at the document() function.

This article provides an overview of its usage.


When I use XML documents in the manner you're describing (i.e. as lookup tables to be referenced during the transform), I generally load them into variables at the top of my transform:

<xsl:stylesheet...>
   <xsl:variable name='resources' select=document('resources.xml')/>
   <xsl:variable name='products' select="$resources/resources/products/product"/>

Then I can look up information from those variables wherever it's appropriate, e.g.:

<xsl:template match='product'>
   <tr>
      <td>
         <xsl:value-of select='@id'/>
      </td>
      <td>
         <xsl:value-of select='@description'/>
      <td>
      <td>
         <img src='{$products[@id=current()/@id]/image}'/>
      </td>
  </tr>
<xsl:template>


Of course, you could use the xsl:document() function twice within the stylesheet. But why do you want to it that way? There seems to be no obvious reason to do so.

Other options are the fn:doc() function of XPath or the xsl:document element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜