2

我有一个公共网站,我需要在该网站上显示我在 SharePoint 中设置的列表视图的简化版本。

我成功地使用此处描述的技术来获取视图的 XML,但它过于复杂,我无法让我的 jQuery AJAX 代码正确处理命名空间。

我已经编写了以下 XSLT,但遇到了问题。提前原谅,因为我是 XSLT 新手。

我的 XLST 看起来像这样:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
     xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
     xmlns:rs='urn:schemas-microsoft-com:rowset'
     xmlns:z='#RowsetSchema'
>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
    <activeRFPs>
    <xsl:for-each select="/xml/rs:data/z:row">
        <rfp>
            <title>
                <xsl:value-of select="@ows_RFP_x0020_Link" />
            </title>
            <applicationStart>
                <xsl:value-of select="@ows_Application_x0020_Period_x0020_S" />
            </applicationStart>
            <applicationEnd>
                <xsl:value-of select="@ows_Application_x0020_Period_x0020_E" />
            </applicationEnd>
            <programStart>
                <xsl:value-of select="@ows_Program_x0020_Start_x0020_Date" />
            </programStart>
            <publicURL>
                <xsl:value-of select="@ows_Public_x0020_Guidelines_x0020_Do" />
            </publicURL>
        </rfp>
    </xsl:for-each>
    </activeRFPs>
</xsl:template>
</xsl:stylesheet>

源 XML 如下所示:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
 xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
 xmlns:rs='urn:schemas-microsoft-com:rowset'
 xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>
  <s:AttributeType name='ows_RFP_x0020_Link' rs:name='RFP Link' rs:number='1'>
     <s:datatype dt:type='string' dt:maxLength='512' />
  </s:AttributeType>
  <s:AttributeType name='ows_Application_x0020_Period_x0020_S' rs:name='Application Period Start Date' rs:number='2'>
     <s:datatype dt:type='datetime' dt:maxLength='8' />
  </s:AttributeType>
  <s:AttributeType name='ows_Application_x0020_Period_x0020_E' rs:name='Application Period End Date' rs:number='3'>
     <s:datatype dt:type='datetime' dt:maxLength='8' />
  </s:AttributeType>
  <s:AttributeType name='ows_Program_x0020_Start_x0020_Date' rs:name='Program Start Date' rs:number='4'>
     <s:datatype dt:type='datetime' dt:maxLength='8' />
  </s:AttributeType>
<s:AttributeType name='ows_Public_x0020_Guidelines_x0020_Do' rs:name='Public Guidelines Doc URL' rs:number='5'>
<s:datatype dt:type='string' dt:maxLength='512' />
</s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ows_RFP_x0020_Link='http://www.google.com, Google Search Engine' ows_Application_x0020_Period_x0020_S='2012-06-22 00:00:00' ows_Application_x0020_Period_x0020_E='2012-07-20 00:00:00' ows_Program_x0020_Start_x0020_Date='2012-10-01 00:00:00' ows_Public_x0020_Guidelines_x0020_Do='http://www.yahoo.com' />
</rs:data>
</xml>

所有值都是 z:row 元素的属性。我对如何使用命名空间有点转变。

当我在 Visual Studio 中运行时,输出的只是:

<?xml version="1.0" encoding="utf-8"?>

<activeRFPs xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" />

我究竟做错了什么?

我想要这样的结构:

<rfp>
<title>value</title>
<applicationStart>value</applicationStart>
<applicationEnd>value</applicationEnd>
...
</rfp>
4

2 回答 2

0

我的猜测是您在 VS 文档属性窗口的输入字段中没有正确设置:

http://msdn.microsoft.com/en-us/library/ms255828.aspx

于 2012-06-26T02:40:23.097 回答
0

你是如何运行转换的?我在 .NET 2.0 中使用一个简单的运行器(添加了缩进)得到了以下输出:

<activeRFPs xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
    <rfp>
        <title>http://www.google.com, Google Search Engine</title>
        <applicationStart>2012-06-22 00:00:00</applicationStart>
        <applicationEnd>2012-07-20 00:00:00</applicationEnd>
        <programStart>2012-10-01 00:00:00</programStart>
        <publicURL>http://www.yahoo.com</publicURL>
    </rfp>
</activeRFPs>

跑步者代码是一些样板:

XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.ConformanceLevel = ConformanceLevel.Fragment;

XmlReaderSettings xslReaderSettings = new XmlReaderSettings();
xslReaderSettings.ProhibitDtd = false;

XmlReader xmlReader = XmlReader.Create(contentFile, xslReaderSettings);
XslReader xslReader = XmlReader.Create(transformFile, xslReaderSettings);
XmlWriter xmlWriter = XmlWriter.Create(outFile, xmlWriterSettings);

XslCompiledTransform xslt = new XslCompiledTransform();
XsltSettings settings = new XsltSettings();
settings.EnableDocumentFunction = true;
settings.EnableScript = true;
xslt.Load(xslReader, settings, new XmlUrlResolver());
xslt.Transform(xmlReader, xmlWriter);

您甚至不需要所有这些设置。

于 2012-06-25T20:01:03.043 回答