0

我在让我的 XML 使用 EXSLT str:replace 模板正确转换时遇到问题。

这是我的 XML:

<XML>
<Item>
    <Field>
        <Name>ID</Name>
        <Value>98765</Value>
    </Field>
    <Field>
        <Name>ParentID</Name>
        <Value>10002</Value>
    </Field>
    <Field>
        <Name>Type</Name>
        <Value>content</Value>
    </Field>
    <Field>
        <Name>Name</Name>
        <Value>TestAPI Course</Value>
    </Field>
    <Field>
        <Name>URL</Name>
        <Value></Value>
    </Field>
    <Field>
        <Name>Description</Name>
        <Value>a description</Value>
    </Field>
    <Field>
        <Name>DateBegin</Name>
        <Value>2012-04-04T00:00:00.000-07:00</Value>
    </Field>
    <Field>
        <Name>DateEnd</Name>
        <Value>2012-04-04T00:00:00.000-08:00</Value>
    </Field>
    <Field>
        <Name>DateCreated</Name>
        <Value>2012-04-03T00:00:00.000-07:00</Value>
    </Field>
    <Field>
        <Name>DateModified</Name>
        <Value>2012-04-04T00:00:00.000-06:00</Value>
    </Field>
</Item>

这是我的 XSL:

<?xml version="1.0" encoding="utf-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str" version="1.0">
        <xsl:import href="C:\inetpub\wwwroot\LMSConnector\LMS\XSL\str.xsl"/>
        <xsl:template match="/Items">
            <xsl:call-template name="str:replace">
                <xsl:with-param name="string" select="Field/Name"/>
                <xsl:with-param name="search" select="ID"/>
                <xsl:with-param name="replace" select="sco-id"/>
            </xsl:call-template>
        </xsl:template>
    </xsl:stylesheet>

我的问题是我只得到一个 XML 文档标题,没有别的,但没有别的?我认为我离一个可行的解决方案还差得很远,问题可能在于我为模板上的“匹配”参数设置的值,以及带有参数节点的调用模板中的选择参数。

任何帮助,将不胜感激。

麦克风

4

1 回答 1

1

您正在尝试匹配<xsl:template match="/Items">,但是您的 XML 包含<Item>元素,而不是<Items>.

编辑


这是你想要做的吗?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str">
    <xsl:import href="http://delicious-library-export.googlecode.com/svn/trunk/str/str.xsl"/>
    <xsl:output method="xml" encoding="utf-8" indent="no"/>

    <xsl:template match="/Item/Field/Name/text()">
        <xsl:call-template name="str:replace">
          <xsl:with-param name="string" select="."/>
          <xsl:with-param name="search" select="'ID'"/>
          <xsl:with-param name="replace" select="'sco-id'"/>
        </xsl:call-template>
    </xsl:template>

    <xsl:template match="*">      
      <xsl:copy>
        <xsl:apply-templates/>
      </xsl:copy>      
    </xsl:template>

    </xsl:stylesheet>

结果:

<?xml version="1.0" encoding="utf-8"?>
<Item>
    <Field>
        <Name>sco-id</Name>
        <Value>98765</Value>
    </Field>
    <Field>
        <Name>Parentsco-id</Name>
        <Value>10002</Value>
    </Field>
    <Field>
        <Name>Type</Name>
        <Value>content</Value>
    </Field>
    <Field>
        <Name>Name</Name>
        <Value>TestAPI Course</Value>
    </Field>
    <Field>
        <Name>URL</Name>
        <Value/>
    </Field>
    <Field>
        <Name>Description</Name>
        <Value>a description</Value>
    </Field>
    <Field>
        <Name>DateBegin</Name>
        <Value>2012-04-04T00:00:00.000-07:00</Value>
    </Field>
    <Field>
        <Name>DateEnd</Name>
        <Value>2012-04-04T00:00:00.000-08:00</Value>
    </Field>
    <Field>
        <Name>DateCreated</Name>
        <Value>2012-04-03T00:00:00.000-07:00</Value>
    </Field>
    <Field>
        <Name>DateModified</Name>
        <Value>2012-04-04T00:00:00.000-06:00</Value>
    </Field>
</Item>
于 2012-04-17T15:52:50.750 回答