以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  [求助]请师兄们帮我看看如何利用xsl获取xml文件中的值并产生相应链接  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=86904)


--  作者:ehrchina
--  发布时间:9/23/2010 9:18:00 AM

--  [求助]请师兄们帮我看看如何利用xsl获取xml文件中的值并产生相应链接
我想实现的效果如下:
按此在新窗口浏览图片

原文地址:http://www.youku.com/v_olist/c_97_a_大陆_fc__fe__s__g_都市_r_2010_d_1_fv_0_fl__o_7.html

下面是我建立的4个筛选字段:
VideoType        视频类型 (多选)     在第一行显示
Country             国家地区  (单选)   在第二行显示
ReleaseYear     上映年份 (单选)      在第三行显示
Initials               首写字母 (单选)    在第四行显示
我想实现的链接模式为:
/Index.aspx?VideoType=0&Country=0&ReleaseYear=0&Initials=0
(这里的VideoType=0 Country=0 ReleaseYear=0  Initials=0 中的 0是根据xml文件中的id来变化  )
链接规律为:当点击其中一行后(如第一行),点击另一行时(如第二行)上一行获取的id不变,仅此行获取的id变化(第一行获取的id不变),以此类推.

我使用的是动易的cms sf3.5  sql2000+net2.0

下面我自己建立了4个文件,师兄们有用到的部分可以把代码直接拷贝过去使用,这样就给您节省下写代码的时间了,在此先感谢各个热心的师兄们,学弟在这里给你带上一份祝福:祝中秋节快乐,祝您身体健康,事事顺利.

我建立了2个xml文件 (由于选项(name)过多,我省略对了一部分,不影响功能的实现)

xml数据部分:dianshiju.xml

<CATALOG>
<VideoType category="1">
<item><name>全部</name><id>0</id></item>
<item><name>爱情</name><id>1</id></item>
<item><name>财经</name><id>2</id></item>
</VideoType>
<Country category="2">
<item><name>全部</name><id>0</id></item>
<item><name>澳大利亚</name><id>1</id></item>
<item><name>大陆</name><id>2</id></item>
</Country>
<ReleaseYear category="3">
<item><name>全部</name><id>0</id></item>
<item><name>2010</name><id>2010</id></item>
<item><name>2009</name><id>2009</id></item>
</ReleaseYear>
<Initials category="4">
<item><name>全部</name><id>0</id></item>
<item><name>A</name><id>1</id></item>
<item><name>B</name><id>2</id></item>
</Initials>
</CATALOG>

xml数据链接部分:dianshiju_y.xml (<ModelID>103</ModelID>这里我选择的模型是相同的,也可以变化)

<NewDataSet>
<table>
<ModelID>103</ModelID>
<Field>
  <ArrayOfFieldInfo>
   <FieldInfo Id="VideoType" name="视频类型" OrderId="1">
     <Settings>
     <string>
  全部|0$$$爱情|1$$$财经|2$$$短片|3
</string>
    </Settings>
   </FieldInfo>
  </ArrayOfFieldInfo>
</Field>
</table>
<table>
<ModelID>103</ModelID>
<Field>
  <ArrayOfFieldInfo>
   <FieldInfo Id="Country" name="国家地区" OrderId="2">
     <Settings>
     <string>
     全部|0$$$澳大利亚|1$$$大陆|2
     </string>
    </Settings>
   </FieldInfo>
  </ArrayOfFieldInfo>
</Field>
</table>

  <table>
<ModelID>103</ModelID>
<Field>
  <ArrayOfFieldInfo>
   <FieldInfo Id="ReleaseYear" name="上映年份" OrderId="3">
     <Settings>
     <string>
     全部|0$$$2010|2010$$$2009|2009
     </string>
    </Settings>
   </FieldInfo>
  </ArrayOfFieldInfo>
</Field>
</table>

   <table>
<ModelID>103</ModelID>
<Field>
  <ArrayOfFieldInfo>
   <FieldInfo Id="Initials" name="首写字母" OrderId="4">
     <Settings>
     <string>
     全部|0$$$A|1$$$B|2
     </string>
    </Settings>
   </FieldInfo>
  </ArrayOfFieldInfo>
</Field>
</table>
</NewDataSet>

xsl文件为2个,其中的代码是抄取其他人的不知是否正确.
第一个xsl文件:
标签(xml数据源调用上面第二个xml)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform" xmlns:pe="labelproc" exclude-result-prefixes="pe">
<xsl:output method="html" />
<xsl:template match="/">
<CATALOG>
<xsl:apply-templates/>
</CATALOG>
</xsl:template>
<xsl:template match="table">
下面的VideoType这样写不知是否正确
<VideoType category="{ModelID}">
<xsl:apply-templates select="Field/ArrayOfFieldInfo/FieldInfo/Settings/string"/>  
</VideoType>
</xsl:template>
以下是我乱添加的
<xsl:template match="table">
<Country category="{ModelID}">
<xsl:apply-templates select="Field/ArrayOfFieldInfo/FieldInfo/Settings/string"/>  
</Country>
</xsl:template>
<xsl:template match="table">
<ReleaseYear category="{ModelID}">
<xsl:apply-templates select="Field/ArrayOfFieldInfo/FieldInfo/Settings/string"/>  
</ReleaseYear>
</xsl:template>
<xsl:template match="table">
<Initials category="{ModelID}">
<xsl:apply-templates select="Field/ArrayOfFieldInfo/FieldInfo/Settings/string"/>  
</Initials>
</xsl:template>
以上是我乱添加的.
<xsl:template match="Settings/string">
<xsl:variable name="v_content" select="."/>

<xsl:call-template name="f-output-item">
<xsl:with-param name="p_content" select="$v_content"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="f-output-item">
<xsl:param name="p_content"/>

<xsl:if test="normalize-space($p_content) != ''">

<xsl:choose>
  <xsl:when test="contains($p_content,'$$$')">
   <xsl:variable name="v_sub_content1" select="substring-before($p_content,'$$$')"/>
   <xsl:variable name="v_sub_content2" select="substring-after($p_content,'$$$')"/>

   <item>
    <name>
<xsl:value-of select="substring-before($v_sub_content1,'|')"/>
</name>
    <id>
<xsl:value-of select="substring-after($v_sub_content1,'|')"/>
</id>
   </item>

   <xsl:call-template name="f-output-item">
    <xsl:with-param name="p_content" select="$v_sub_content2"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
   <item>
    <name>
<xsl:value-of select="substring-before($p_content,'|')"/>
</name>
    <id>
<xsl:value-of select="substring-after($p_content,'|')"/>
</id>
   </item>
  </xsl:otherwise>
</xsl:choose>

</xsl:if>

</xsl:template>
</xsl:stylesheet>


第二个xsl文件:
标签(xml数据源调用第一个xml),筛选的链接部分,这里我想实现这样的效果:
/Index.aspx?VideoType=0&Country=0&ReleaseYear=0&Initials=0

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform" xmlns:pe="labelproc" exclude-result-prefixes="pe">
<xsl:param name="modeId" />
<xsl:param name="nodeId" />
<xsl:param name="videotypeId" />
<xsl:param name="CountryId" />
<xsl:param name="ReleaseYearId" />
<xsl:param name="InitialsId" />
<xsl:output method="html" />
<xsl:template match="/">
以下内容是抄的人家的
<xsl:for-each select="/CATALOG/edition[@category=$modeId]/item">
<li id="MenuID_2_{position()-1}">
<a href="/Category_{$nodeId}/Index.aspx?edition={id}">
<xsl:value-of select="name"/>
</a>
</li>
</xsl:for-each>
以上内容是抄的人家的
</xsl:template>
</xsl:stylesheet>


假如有更好的办法,也可以写出来,在此感谢师兄师姐们了.



--  作者:ehrchina
--  发布时间:9/24/2010 10:29:00 AM

--  
zijiding
--  作者:ehrchina
--  发布时间:9/24/2010 10:29:00 AM

--  
zijiding
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
77.148ms