xsl-list
[Top] [All Lists]

Calling templates based on node contents

2004-08-18 03:25:41
Hi All...

Have a little problem. Basically I have this XML structure:

<contentTable>
  <contentPage hasContent="1">
    <contentField ID="0" UID="31">
      <contentFieldID>0</contentFieldID>
      <contentFieldUID>31</contentFieldUID>
      <contentFieldName>new_Content_Field_0</contentFieldName>
      <contentFieldStyle>default</contentFieldStyle>
      <contentFieldElement>defaultField</contentFieldElement>
      <contentFieldHR>True</contentFieldHR>
      <contentFieldBTT>False</contentFieldBTT>
      <contentFieldValue>
        <contentItem ID="0">
          <contentItemValue type="text">Default text</contentItemValue>
          <contentItemValue type="label">Default label</contentItemValue>
          <contentItemValue type="url">Default url text</contentItemValue>
          <contentItemValue type="file">Default file text</contentItemValue>
          <contentItemValue type="DLfile">Default download 
text</contentItemValue>
        </contentItem>
      </contentFieldValue>
    </contentField>
  </contentPage>
</contentTable>

From this I need to generate html output. There are many different types of 
style and element that can be put into this XML and have generated templates 
for these.

From these two nodes I want to call templates that format the XML accordingly.

I have got this far but im really stuck on how to call different templates 
based upon the contents of these nodes.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
        
        <xsl:template match="." mode="defaultField_default">
                <xsl:param name="style"/>
                <span class="{$style}">
                        <xsl:value-of 
select="contentItem/contentItemValue[(_at_)type='text']"/>
                </span>
        </xsl:template>
        
        <xsl:template match="." mode="defaultField_A">
                <xsl:param name="style"/>
                <a class="{$style}" 
href="{contentItem/contentItemValue[(_at_)type='url']}">
                        <xsl:value-of 
select="contentItem/contentItemValue[(_at_)type='text']"/>
                </a>
        </xsl:template>
        
        <xsl:template match="contentPage">
                <xsl:for-each select="contentField">
                        <xsl:sort select="@ID" order="ascending" 
data-type="number"/>
                        <xsl:apply-templates mode="defaultField_A" 
select="contentFieldValue">
                                <xsl:with-param name="style" 
select="concat(contentFieldElement, '_', contentFieldStyle)"/>
                        </xsl:apply-templates>
                </xsl:for-each>
        </xsl:template>
        
</xsl:stylesheet>

Currently all of the contentFields go through the <xsl:template match="." 
mode="defaultField_A"> template. 

Any help on this would be fantastic.

Thanks in advance.

Ben

This e-mail and any attached files are for the exclusive use of the addressee 
and may contain privileged and/or confidential information. If you receive this 
e-mail in error you should not disclose the contents to any other person nor 
take copies but should delete it and telephone us immediately on +44(0)20 7557 
6100.

TEQUILA\ London Limited does not make any warranty as to the accuracy or 
completeness of this e-mail and we accept no liability for its content or use. 
Any opinions expressed in this e-mail are those of the author and do not 
necessarily reflect the opinions of TEQUILA\ London Limited.

TEQUILA\ London Limited operates within the parameters set by the Data 
Protection Act 1998 with regard to the use of personal information including 
e-mail addresses. We accept no liability for the forwarding of this e-mail to 
other parties that may result in unsolicited e-mails being received by those 
whose email addresses appear in this e-mail.