【问题标题】:start ul li as specific position from xml file从 xml 文件开始 ul li 作为特定位置
【发布时间】:2013-04-30 15:45:39
【问题描述】:

这是 xml 文件:-

  <?xml-stylesheet type="text/xsl" href="m.xsl"?> 
<root>
    <child_1 entity_id="1" value="Root Catalog" parent_id="0">
        <child_2 entity_id="2" value="Navigate" parent_id="1">
            <child_4 entity_id="4" value="Activities" parent_id="2">
                <child_10066 entity_id="10066" value="Physical1" parent_id="4">
                    <child_10067 entity_id="10067" value="Cricket" parent_id="10066">
                        <child_10068 entity_id="10068" value="One Day" parent_id="10067"/>
                    </child_10067>
                </child_10066>
                <child_10069 entity_id="10069" value="Test2" parent_id="4"/>
                <child_10070 entity_id="10070" value="Test3" parent_id="4"/>
                <child_10071 entity_id="10071" value="Test4" parent_id="4"/>
                <child_10072 entity_id="10072" value="Test5" parent_id="4"/>
                <child_5 entity_id="5" value="Physical" parent_id="4"/>
            </child_4>
            <child_4331 entity_id="4331" value="Region" parent_id="2">
                <child_4332 entity_id="4332" value="Asia" parent_id="4331">
                    <child_4333 entity_id="4333" value ="India" parent_id="4332">
                        <child_4334 entity_id ="4334" value = "Gujarat" parent_id="4333"/>
                    </child_4333>
                </child_4332>
            </child_4331>
        </child_2>
    </child_1>
</root> 

这里我使用的是这种类型的 xslt:-

   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="*" mode="item">
    <li>
      <xsl:value-of select="@value" />
      <xsl:apply-templates select="current()[*]" />
    </li>
  </xsl:template>

  <xsl:template match="*/*/*">
    <ul> 
      <xsl:if test="local-name(parent::*) = 'root'"><xsl:attribute name="id"><xsl:text disable-output-escaping="yes">first</xsl:text> </xsl:attribute></xsl:if>
      <xsl:apply-templates select="*[1] | node()[current()/ancestor::*[3]]" mode="item"/>
    </ul>
  </xsl:template>
</xsl:stylesheet>

这个 xslt 输出是:-

  • 活动
    • 物理1
      • 蟋蟀
        • 一天
    • 测试2
    • 测试3
    • 测试4
    • 测试5
    • 物理

设置第一个 ul id id="frist"

如何使用 xslt... 谢谢...

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    更改您当前的模板:

      <xsl:template match="*/*">
        <ul> 
        <xsl:if test="local-name(parent::*) = 'root'"><xsl:attribute name="id"><xsl:text disable-output-escaping="yes">first</xsl:text> </xsl:attribute></xsl:if>
        <xsl:apply-templates select="*[1] | node()[current()/ancestor::*[3]]" mode="item"/>
        </ul>
      </xsl:template>
    

    用这个:

      <xsl:template match="*/*/*">
        <ul> 
          <xsl:if test="local-name(parent::*) = 'root'"><xsl:attribute name="id"><xsl:text disable-output-escaping="yes">first</xsl:text> </xsl:attribute></xsl:if>
          <xsl:apply-templates select="*[1] | node()[current()/ancestor::*[3]]" mode="item"/>
        </ul>
      </xsl:template>
    

    【讨论】:

    • 是的,我正在使用上面的模板,但没有在 ul 检查中插入 id,我已经删除了完全愚蠢的代码并更新了新代码,它的帮助完全可以查看我的系统中的问题在哪里...跨度>
    猜你喜欢
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    相关资源
    最近更新 更多