Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2007, 02:41 PM
Authorized User
 
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default call template from diff file? (import vs. include)

How can I put the last template shown here into another file and still call it? Whenever I use an "import" or "include" in conjunction with "call-templates", it doesn't seem to work. =(

[u]MyData.xml</u>
Code:
<Collection>
  <Content>
    <Title>3200 Conference Room</Title>
    <Type>Content</Type>
    <Link>content.aspx?id=123</Link>
  </Content>
  <Content>
    <Title>Atrium</Title>
    <Type>Asset</Type>
    <Link>content.aspx?id=456</Link>
  </Content>
</Collection>
[u]myTemplates.xslt</u>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
      <xsl:for-each select="Collection/Content">
        <xsl:if test="Title != 'Placeholder'">
          <xsl:apply-templates select="." mode="output" />
        </xsl:if>
      </xsl:for-each>
  </xsl:template>

  <xsl:template match="*" mode="output">
    <a href="{Link}">
      <xsl:value-of select="Title"/><br />
    </a>
  </xsl:template>

</xsl:stylesheet>
I'm trying to seperate the template directly above into a seperate XSLT file but still be able to call it from "myTemplates.xslt". Can you help me?????

Thanks!
Steve
 
Old January 30th, 2007, 03:55 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can't help you if I'm blindfolded. I need to know what you did and I need to know what error messages (or incorrect output) you got. Telling me "I did something and it didn't work" is no use at all.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 30th, 2007, 06:05 PM
Authorized User
 
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When I use an "import" or "include" statement, it produces nothing - just a blank page.

Steve

 
Old January 31st, 2007, 06:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Then you did it wrong. To help you find the bug in your code, I need to see your code.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 31st, 2007, 12:06 PM
Authorized User
 
Join Date: Jan 2007
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is exactly what I've got so far:

[u]meeting_rooms_list.xsl</u>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:include href="generic_bullet_import.xsl"/>
  <xsl:template match="/">
    <table border="0" cellspacing="0" cellpadding="0">
      <xsl:for-each select="Collection/Content">
        <xsl:if test="Title!='Public Meeting Rooms Homepage'">
          <xsl:call-template name="generic_bullet">
            <xsl:with-param name="type" select="Type" />
            <xsl:with-param name="id" select="ID" />
            <xsl:with-param name="link" select="QuickLink" />
            <xsl:with-param name="title" select="Title" />
          </xsl:call-template>
        </xsl:if>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>
[u]generic_bullet_import.xsl</u>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template name="generic_bullet">
    <xsl:param name="type" />
    <xsl:param name="id" />
    <xsl:param name="link" />
    <xsl:param name="title" />
    <tr>
      <td valign="top">
        <img src="http://172.16.2.33/images/global/bullet.gif" style="padding: 8px 8px 0px 4px;" />
      </td>
      <td>
        <a>
          <xsl:attribute name="href">
            <xsl:choose>
              <xsl:when test="$type = 'Assets' or $type = 8 ">
                javascript:void window.open('/WorkArea/showcontent.aspx?id=<xsl:value-of select="$id"/>','showcontent','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700,height=600')
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="$link"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
          <xsl:value-of select="$title"/>
        </a>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>
it produces a blank page.

Steve
 
Old January 31st, 2007, 07:12 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When I run your stylesheet in Saxon I get this output:

<?xml version="1.0" encoding="UTF-8"?>
<table border="0" cellspacing="0" cellpadding="0">
   <tr>
      <td valign="top">
         <img src="http://172.16.2.33/images/global/bullet.gif"
              style="padding: 8px 8px 0px 4px;"/>
      </td>
      <td>
         <a href="">3200 Conference Room</a>
      </td>
   </tr>
   <tr>
      <td valign="top">
         <img src="http://172.16.2.33/images/global/bullet.gif"
              style="padding: 8px 8px 0px 4px;"/>
      </td>
      <td>
         <a href="">Atrium</a>
      </td>
   </tr>
</table>

How are you running it?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl import/include mapping sammyj727 XSLT 3 July 19th, 2007 04:15 PM
xsl:include / import and tomcat amitda XSLT 2 April 17th, 2007 10:37 AM
difference between include file & include virtual crmpicco Classic ASP Basics 2 January 23rd, 2006 11:50 AM
Apply Custom template & import data from text file shampabera Excel VBA 2 August 8th, 2005 07:41 AM
import / call / template match Kabe XSLT 3 February 26th, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.