<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:param name="contextPath">CONTEXT_PATH/</xsl:param>
<xsl:include href="xhtml.xsl"/>
<xsl:variable name="site"><xsl:value-of select="/leftnavigation/tree/path/node[2]/@name"/></xsl:variable>
<xsl:template match="leftnavigation">
<xsl:element name="h1">
<xsl:attribute name="id">banner</xsl:attribute>
<xsl:apply-templates select="bannerleftimage" />
<xsl:apply-templates select="bannermiddleimage" />
<xsl:if test="$site='Families'">
<xsl:apply-templates select="bannerrightimage" />
<!-- Just to output the value for dev purposes -->
<xsl:text><xsl:value-of select="$site"/></xsl:text>
</xsl:if>
</xsl:element>
<xsl:element name="div">
<xsl:attribute name="id">left_col</xsl:attribute>
<xsl:apply-templates select="sectionlist" />
</xsl:element>
</xsl:template>
<xsl:template match="bannerleftimage">
<xsl:variable name="currentsrc" select="@filename"/>
<xsl:variable name="origwidth">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@width"/>
</xsl:variable>
<xsl:variable name="origheight">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@height"/>
</xsl:variable>
<xsl:variable name="ratio">
<xsl:value-of select="$origwidth div $origheight"/>
</xsl:variable>
<xsl:variable name="origalt">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@alt"/>
</xsl:variable>
<xsl:variable name="origtitle">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@title"/>
</xsl:variable>
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="$contextPath"/>/home.html</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="$contextPath"/>/images/banners/<xsl:value-of select="@filename"/></xsl:attribute>
<xsl:attribute name="width">365</xsl:attribute>
<xsl:attribute name="height">100</xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="$origtitle"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="$origalt"/></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="bannermiddleimage">
<xsl:variable name="currentsrc" select="@filename"/>
<xsl:variable name="origwidth">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@width"/>
</xsl:variable>
<xsl:variable name="origheight">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@height"/>
</xsl:variable>
<xsl:variable name="ratio">
<xsl:value-of select="$origwidth div $origheight"/>
</xsl:variable>
<xsl:variable name="origalt">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@alt"/>
</xsl:variable>
<xsl:variable name="origtitle">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@title"/>
</xsl:variable>
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="$contextPath"/>/home.html</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="id">banmiddle</xsl:attribute>
<xsl:attribute name="src"><xsl:value-of select="$contextPath"/>/images/banners/<xsl:value-of select="@filename"/></xsl:attribute>
<xsl:attribute name="width">1</xsl:attribute>
<xsl:attribute name="height">100</xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="$origtitle"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="$origalt"/></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="bannerrightimage">
<xsl:variable name="currentsrc" select="@filename"/>
<xsl:variable name="origwidth">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@width"/>
</xsl:variable>
<xsl:variable name="origheight">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@height"/>
</xsl:variable>
<xsl:variable name="ratio">
<xsl:value-of select="$origwidth div $origheight"/>
</xsl:variable>
<xsl:variable name="origalt">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@alt"/>
</xsl:variable>
<xsl:variable name="origtitle">
<xsl:value-of select="//gallery/image[@filename=$currentsrc]/@title"/>
</xsl:variable>
<xsl:element name="div">
<xsl:attribute name="id">bannerright</xsl:attribute>
<xsl:element name="div">
<xsl:attribute name="id">talktoexpert</xsl:attribute>
<xsl:attribute name="title">Talk to a specialist consultant</xsl:attribute>
Talk to a specialist consultant
</xsl:element>
<xsl:element name="div">
<xsl:attribute name="id">bannertel</xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="$origtitle"/></xsl:attribute>
<xsl:value-of select="../telephone"/>
</xsl:element>
<xsl:element name="div">
<xsl:attribute name="id">bannertelint</xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="$origtitle"/></xsl:attribute>
<xsl:value-of select="../telephoneint"/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="sectionlist">
<xsl:element name="ul">
<xsl:attribute name="id">side_menu</xsl:attribute>
<xsl:for-each select="section">
<xsl:element name="li">
<xsl:if test="@cssclass">
<xsl:attribute name="class"><xsl:value-of select="@cssclass"/></xsl:attribute>
</xsl:if>
<xsl:if test="@cssid">
<xsl:attribute name="id"><xsl:value-of select="@cssid"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="xhtml"/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:stylesheet>
То, что я пытаюсь достичь:
Я пытаюсь установить состояние вокруг шаблона (bannerrightimage
) не появляется для конкретной марки (в вашем случае String) называется 'Families'
. @name
обычно возвращает три строки, Families
, Children
, Adults
. И он работает в моих других файлах xsl.переменная XSL не передавая значения в
Проблема, с которой я сталкиваюсь, заключается в том, что переменная $site
не передает никаких значений. но если я что-то вроде:
<xsl:variable name="site"><xsl:text>ABC123</xsl:text>
$site
делает выходной ABC123. Как я уже говорил раньше, если я в home.xsl я бы свою переменную как:
home.xsl
<xsl:variable name="site"><xsl:value-of select="/home/tree/path/node[2]/@name"/>
и если это country.xsl я установил бы свою переменную как:
<xsl:variable name="site"><xsl:value-of select="/country/tree/path/node[2]/@name"/>
home.xsl и country.xsl работа прекрасно, но когда я реализую один и тот же стиль для моего leftnavigation.xsl$site
не возвращает никакого значения. даже не пустое место ...
Поскольку похоже, что вы ничего не выбираете в своем исходном XML, это поможет, если вы также продемонстрируете часть XML, с которой работаете. Кроме того, ваши фрагменты кода для '$ site' имели бы больше смысла, если бы вы включили конечные теги. В-третьих, ' ABC123 xsl: variable>' может быть ' ' и ' xsl: variable> 'может быть' ' –
@TonyGraham Я редактировал сообщение, чтобы источник мог включать все, что я вызываю и использую. Кроме того, я пробовал все эти стили с точки зрения того, что он похож на ' ', как вы упомянули. Но после попытки, как 5000 раз, я закончил эту нелепую конвенцию, и я оставил ее в этом состоянии (пока). –
Arty
Извините, я хотел бы видеть ваш хорошо сформированный исходный XML-код, который начинается с '' и включает в себя до второго '', поэтому мы можем видеть, насколько ваш XPath соответствует вашей структуре. –