최근까지는 XSLT가 완전히 새로운 것이기까지 잠시 동안 Dynamicweb이라는 덴마크 CMS가있는 메뉴/하위 메뉴에서 작업했습니다.어린이가 XSLT를 사용하는 경우 부모 요소에 클래스를 지정하십시오.
Dynamicweb 특정 질문 또는 XSLT 관련 질문 인 경우 알 수 없지만 어쨌든 물어 봅니다.
나의 현재 XSLT 문서는 다음과 같습니다
<xsl:template match="//Page">
<xsl:param name="depth"/>
<li>
<xsl:attribute name="id">
<xsl:value-of select="concat('', translate(translate(@MenuText, translate(@MenuText, $validRange, ''), ''), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))" />
</xsl:attribute>
<a>
<xsl:attribute name="class">
<!-- Add .inpath class -->
<xsl:if test="@InPath='True'">
<xsl:text> inpath</xsl:text>
</xsl:if>
<!-- Add .firstitem class -->
<xsl:if test="position() = 1">
<xsl:text> firstitem</xsl:text>
</xsl:if>
<!-- Add .miditem class -->
<xsl:if test="position() > 1 and position() < count(//Page)">
<xsl:text> miditem</xsl:text>
</xsl:if>
<!-- Add .lastitem class -->
<xsl:if test="position() = count(//Page)">
<xsl:text> lastitem</xsl:text>
</xsl:if>
<!-- Add .active class -->
<xsl:if test="@Active = 'True'">
<xsl:text> active</xsl:text>
</xsl:if>
</xsl:attribute>
<!-- Add link ID (URL friendly menu text) -->
<xsl:attribute name="id">
<xsl:value-of select="concat('anchor-', translate(translate(@MenuText, translate(@MenuText, $validRange, ''), ''), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))" />
</xsl:attribute>
<!-- Add link URL -->
<xsl:attribute name="href">
<xsl:value-of select="@FriendlyHref" disable-output-escaping="yes" />
</xsl:attribute>
<!-- Add link text -->
<span><xsl:value-of select="@MenuText" disable-output-escaping="yes" /></span>
</a>
<xsl:if test="count(Page) and @MenuText != 'Home'">
<ul class="level{@AbsoluteLevel+1}">
<xsl:apply-templates select="Page">
<xsl:with-param name="depth" select="$depth+1"/>
</xsl:apply-templates>
</ul>
</xsl:if>
</li>
</xsl:template>
당신은 내가 active
및 inpath
에 대한 Dynamicweb 태그를 기반으로 클래스를 추가하는 방법을 볼 수 있습니다. 문제는 문서
(여기에 붙여 넣지 않음)에 있습니다.
은 하위 메뉴 (ul
및 li
)를 인쇄하는 코드입니다. 하위 메뉴 항목을 클릭하면 해당 항목은 active
클래스가되지만 부모에게 active
클래스도 제공 할 수 있습니까?
업데이트 : 원시 XML (지저분한 XML에 대해 유감입니다)이 추가되었습니다.
<?xml version="1.0" encoding="utf-8"?>
<NavigationTree>
<Settings>
<Pageview ID="1" AreaID="1" MenuText="Home" Title="Home" NavigationName="" />
<Setting Level="1">
<NavigationImage Value="" />
<NavigationMouseoverImage Value="" />
<NavigationActiveImage Value="" />
<NavigationImgAfter Value="" />
<NavigationDividerImage Value="" />
<NavigationHideSpacer Value="True" />
<NavigationSpace Value="0" />
</Setting>
<Setting Level="2">
<NavigationImage Value="" />
<NavigationMouseoverImage Value="" />
<NavigationActiveImage Value="" />
<NavigationImgAfter Value="" />
<NavigationDividerImage Value="" />
<NavigationHideSpacer Value="" />
<NavigationSpace Value="0" />
</Setting>
<Setting Level="3">
<NavigationImage Value="" />
<NavigationMouseoverImage Value="" />
<NavigationActiveImage Value="" />
<NavigationImgAfter Value="" />
<NavigationDividerImage Value="" />
<NavigationHideSpacer Value="" />
<NavigationSpace Value="0" />
</Setting>
<Setting Level="4">
<NavigationImage Value="" />
<NavigationMouseoverImage Value="" />
<NavigationActiveImage Value="" />
<NavigationImgAfter Value="" />
<NavigationDividerImage Value="" />
<NavigationHideSpacer Value="" />
<NavigationSpace Value="3" />
</Setting>
<Setting Level="5">
<NavigationImage Value="" />
<NavigationMouseoverImage Value="" />
<NavigationActiveImage Value="" />
<NavigationImgAfter Value="" />
<NavigationDividerImage Value="" />
<NavigationHideSpacer Value="" />
<NavigationSpace Value="3" />
</Setting>
</Settings>
<Page ID="1" AreaID="1" MenuText="Home" MouseOver="" Href="Default.aspx?ID=1" FriendlyHref="/default/home.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="1" RelativeLevel="1" Sort="1" LastInLevel="False" InPath="True" ChildCount="3" class="L1_Active" Active="True" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True">
<Page ID="6" AreaID="1" MenuText="News" MouseOver="" Href="Default.aspx?ID=6" FriendlyHref="/default/home/news.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="2" RelativeLevel="2" Sort="1" LastInLevel="False" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
<Page ID="7" AreaID="1" MenuText="About" MouseOver="" Href="Default.aspx?ID=7" FriendlyHref="/default/home/about.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="2" RelativeLevel="2" Sort="2" LastInLevel="False" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
<Page ID="8" AreaID="1" MenuText="Presence" MouseOver="" Href="Default.aspx?ID=8" FriendlyHref="/default/home/presence.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="2" RelativeLevel="2" Sort="3" LastInLevel="True" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
</Page>
<Page ID="2" AreaID="1" MenuText="Hygiene" MouseOver="" Href="Default.aspx?ID=14" FriendlyHref="/default/hygiene.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="False" ShowInSitemap="True" AbsoluteLevel="1" RelativeLevel="1" Sort="2" LastInLevel="False" InPath="False" ChildCount="2" class="L1" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True">
<Page ID="14" AreaID="1" MenuText="Professional" MouseOver="" Href="Default.aspx?ID=14" FriendlyHref="/default/hygiene/professional.aspx" Image="/Files/Navigation/menu_antibac_01.gif" ImageActive="/Files/Navigation/menu_antibac_02.gif" ImageMouseOver="/Files/Navigation/menu_antibac_02.gif" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="2" RelativeLevel="2" Sort="1" LastInLevel="False" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
<Page ID="15" AreaID="1" MenuText="Private" MouseOver="" Href="Default.aspx?ID=15" FriendlyHref="/default/hygiene/private.aspx" Image="/Files/Navigation/menu_antibac_01.gif" ImageActive="/Files/Navigation/menu_antibac_02.gif" ImageMouseOver="/Files/Navigation/menu_antibac_02.gif" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="2" RelativeLevel="2" Sort="2" LastInLevel="True" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
</Page>
<Page ID="3" AreaID="1" MenuText="Household & Leisure" MouseOver="" Href="Default.aspx?ID=3" FriendlyHref="/default/household---leisure.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="1" RelativeLevel="1" Sort="3" LastInLevel="False" InPath="False" ChildCount="0" class="L1" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
<Page ID="4" AreaID="1" MenuText="Car Care" MouseOver="" Href="Default.aspx?ID=4" FriendlyHref="/default/car-care.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="1" RelativeLevel="1" Sort="4" LastInLevel="False" InPath="False" ChildCount="1" class="L1" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True">
<Page ID="20" AreaID="1" MenuText="Carix" MouseOver="" Href="Default.aspx?ID=20" FriendlyHref="/default/car-care/carix.aspx" Image="/Files/Navigation/menu_carix_01.gif" ImageActive="/Files/Navigation/menu_carix_02.gif" ImageMouseOver="/Files/Navigation/menu_carix_02.gif" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="2" RelativeLevel="2" Sort="1" LastInLevel="True" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
</Page>
<Page ID="5" AreaID="1" MenuText="Industrial Chemicals" MouseOver="" Href="Default.aspx?ID=5" FriendlyHref="/default/industrial-chemicals.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" AbsoluteLevel="1" RelativeLevel="1" Sort="5" LastInLevel="True" InPath="False" ChildCount="0" class="L1" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" />
</NavigationTree>
예, 할 수있는 방법이 있습니다 (아마도). 어쨌든, 나는 XSLT를 작성하고 테스트하기 위해 샘플 입력 문서가 필요할 것이다. 질문에 하나를 추가하십시오. :) – Tomalak
귀하의 XML은 모두 소문자이며, 귀하의 XSLT는 대소 문자가 혼용됩니다. 뭐가 맞습니까? – Tomalak
죄송합니다, 나는 XML을 prettifier 통해 넣어 : P 혼합 경우가 맞습니다! –