以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 XQuery/XLink/XPointer/ 』  (http://bbs.xml.org.cn/list.asp?boardid=14)
----  源文件 和问题贴出来了,给我帮助  (http://bbs.xml.org.cn/dispbbs.asp?boardid=14&rootid=&id=24429)


--  作者:pingosk
--  发布时间:11/18/2005 11:03:00 PM

--  源文件 和问题贴出来了,给我帮助
部分要转换的xml文件
<?xml version="1.0" encoding="utf-8" ?>
<Report>
<x:PivotField>
   <x:Name>Product Family</x:Name>
   <x:SourceName>[Product].[Product Family]</x:SourceName>
   <x:FilterCaption>Product</x:FilterCaption>
   <x:Orientation>Row</x:Orientation>
   <x:CompareOrderedMembersBy>UniqueName</x:CompareOrderedMembersBy>
   <x:AllIncludeExclude>Include</x:AllIncludeExclude>
   <x:ExcludedMember>
    <x:Name>Non-Consumable</x:Name>
    <x:UniqueName>[Product].[All Products].[Non-Consumable]</x:UniqueName>
   </x:ExcludedMember>
  </x:PivotField>
  <x:PivotField>
   <x:Name>Product Department</x:Name>
   <x:SourceName>[Product].[Product Department]</x:SourceName>
   <x:Orientation>Row</x:Orientation>
   <x:Position>2</x:Position>
   <x:CompareOrderedMembersBy>UniqueName</x:CompareOrderedMembersBy>
   <x:ExcludedMember>
    <x:Name>Dairy</x:Name>
    <x:UniqueName>[Product].[All Products].[Food].[Dairy]</x:UniqueName>
   </x:ExcludedMember>
   <x:ExcludedMember>
    <x:Name>Baked Goods</x:Name>
    <x:UniqueName>[Product].[All Products].[Food].[Baked Goods]</x:UniqueName>
   </x:ExcludedMember>
  </x:PivotField>
  <x:PivotField>
   <x:Name>Product Category</x:Name>
   <x:SourceName>[Product].[Product Category]</x:SourceName>
   <x:Orientation>Row</x:Orientation>
   <x:Position>3</x:Position>
   <x:CompareOrderedMembersBy>UniqueName</x:CompareOrderedMembersBy>
  </x:PivotField>
  <x:PivotField>
   <x:Name>Product Subcategory</x:Name>
   <x:SourceName>[Product].[Product Subcategory]</x:SourceName>
   <x:Orientation>Row</x:Orientation>
   <x:Position>4</x:Position>
   <x:CompareOrderedMembersBy>UniqueName</x:CompareOrderedMembersBy>
   <x:IncludedMember>
    <x:Name>Bagels</x:Name>
    <x:UniqueName>[Product].[All Products].[Food].[Baked Goods].[Bread].[Bagels]</x:UniqueName>
   </x:IncludedMember>
   <x:IncludedMember>
    <x:Name>Sliced Bread</x:Name>
    <x:UniqueName>[Product].[All Products].[Food].[Baked Goods].[Bread].[Sliced Bread]</x:UniqueName>
   </x:IncludedMember>
  </x:PivotField>
  <x:PivotField>
   <x:Name>Brand Name</x:Name>
   <x:SourceName>[Product].[Brand Name]</x:SourceName>
   <x:Orientation>Row</x:Orientation>
   <x:Position>5</x:Position>
   <x:CompareOrderedMembersBy>UniqueName</x:CompareOrderedMembersBy>
   <x:ExcludedMember>
    <x:Name>Colony</x:Name>
    <x:UniqueName>[Product].[All Products].[Food].[Baked Goods].[Bread].[Sliced Bread].[Colony]</x:UniqueName>
   </x:ExcludedMember>
  </x:PivotField>
  <x:PivotField>
   <x:Name>Product Name</x:Name>
   <x:SourceName>[Product].[Product Name]</x:SourceName>
   <x:CompareOrderedMembersBy>UniqueName</x:CompareOrderedMembersBy>
  </x:PivotField>
</Report>
解释:
这是一个多维的数据
所有x:SourceName  中第一个[]内相同的都 是一个维,,然后一个维可以有多个级别
[Product].[Product Family]
[Product].[Product Department],[Product].[Product Category]
[Product].[Product Subcategory]
[Product].[Brand Name]
[Product].[Product Name]都 是product的级别


现在我想完成这样一个任务:
我首先选择在poduct维度中的所有excludedmember元素
<xsl:for-each select="//x:ExcludedMember[substring-before(x:UniqueName,'.')='[Product']">

第二步 我想选择它的x:ExcludedMember子元素(可能很多),x:ExcludedMember底下有x:UniqueName元素.
文档中的其它地方还有x:IncludedMember/x:UniqueName元素,问题是我不想选择满足starts-with(文档中任何x:IncludedMember/x:UniqueName,我当前处理的x:ExcludedMember的x:UniqueName)的那些x:ExcludeMember元素,于是我又加了句这样的代码

not (//x:IncludedMember[starts-with(x:UniqueName,./x:UniqueName)])]">
然后我想把所有的这样的元素的x:UniqueName用,号连起来,但最后一个不要

所以 总的xsl代码 是
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:x="urn:schemas-microsoft-com:office:excel">
<xsl:template name="add">
<xsl:for-each select="//x:ExcludedMember[substring-before(x:UniqueName,'.')='[Product'][not (//x:IncludedMember[starts-with(x:UniqueName,current()/x:UniqueName)])]">
Descendants(<xsl:value-of select="x:UniqueName" />)     <xsl:if test="position()!=last()">
    ,
    </xsl:if>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
但结果和我想要的是不同的,

不知该如何是好
(中间在贴的时候.有所修改,有点语法错误,见谅,我不会出那方面的原因)

[此贴子已经被作者于2005-11-19 12:49:56编辑过]

--  作者:菜籽
--  发布时间:11/19/2005 10:43:00 AM

--  
<xsl:template>
</xsl:stylesheet>
应该是
</xsl:template>
</xsl:stylesheet>

--  作者:pingosk
--  发布时间:11/19/2005 12:49:00 PM

--  
对,,我马上改过来
--  作者:菜籽
--  发布时间:11/19/2005 2:17:00 PM

--  
这样可以么?

<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:x="urn:schemas-microsoft-com:office:excel">
<xsl:template name="add">
<xsl:for-each select="//x:ExcludedMember[substring-before(x:UniqueName,'.')='[Product'][not (//x:IncludedMember[starts-with(x:UniqueName,//x:ExcludedMember/x:UniqueName)])]">
Descendants(<xsl:value-of select="x:UniqueName" />)     <xsl:if test="position()!=last()">
    ,
    </xsl:if>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>



--  作者:pingosk
--  发布时间:11/19/2005 3:05:00 PM

--  
我试试看
--  作者:pingosk
--  发布时间:11/20/2005 2:05:00 PM

--  
不行啊,大哥
--  作者:pingosk
--  发布时间:11/20/2005 3:46:00 PM

--  
以下是我的解决方法
 <xsl:template name="FilterExcludedMember">
  <xsl:param name="Index" select="1" />
  <xsl:param name="Visited" select="0" /><!--这里为什么不能用字符串"False"-->
  <xsl:param name="Super" />
  <xsl:if test="$Index &lt;= count(//x:ExcludedMember)">
   <xsl:variable name="Temp" select="//x:ExcludedMember[substring-before(x:UniqueName,'.')=substring-before($Super,'.')][position()=$Index]/x:UniqueName" />
   <xsl:choose>
    <xsl:when test="not (//x:IncludedMember[starts-with(x:UniqueName,$Temp)]) and $Visited =0">
    Descendants(<xsl:value-of select="$Temp" />)
    <xsl:call-template name="FilterExcludedMember">
      <xsl:with-param name="Visited">
       <xsl:value-of select="1" />
      </xsl:with-param>
      <xsl:with-param name="Index">
       <xsl:value-of select="$Index + 1" />
      </xsl:with-param>
      <xsl:with-param name="Super">
       <xsl:value-of select="$Super" />
      </xsl:with-param>
     </xsl:call-template>
    </xsl:when>
    <xsl:when test="not (//x:IncludedMember[starts-with(x:UniqueName,$Temp)]) and $Visited =1">
    ,Descendants(<xsl:value-of select="$Temp" />)
    <xsl:call-template name="FilterExcludedMember">
      <xsl:with-param name="Visited">
       <xsl:value-of select="1" />
      </xsl:with-param>
      <xsl:with-param name="Index">
       <xsl:value-of select="$Index + 1" />
      </xsl:with-param>
      <xsl:with-param name="Super">
       <xsl:value-of select="$Super" />
      </xsl:with-param>
     </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
     <xsl:call-template name="FilterExcludedMember">
      <xsl:with-param name="Visited">
       <xsl:value-of select="$Visited" />
      </xsl:with-param>
      <xsl:with-param name="Index">
       <xsl:value-of select="$Index + 1" />
      </xsl:with-param>
      <xsl:with-param name="Super">
       <xsl:value-of select="$Super" />
      </xsl:with-param>
     </xsl:call-template>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
  <xsl:if test="$Index &gt; count(//x:ExcludedMember) and //x:PivotField[x:IncludedMember][substring-before(x:SourceName,']')=substring-before($Super,']')] and $Visited =1 ">
        ,
   </xsl:if>
 </xsl:template>
--  作者:菜籽
--  发布时间:11/20/2005 11:06:00 PM

--  
你的问题解决了么?
--  作者:pingosk
--  发布时间:11/21/2005 5:06:00 PM

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