0

EXSLT str:replace テンプレートを使用して XML を正しく変換する際に問題が発生しています。

ここに私の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 ドキュメント ヘッダーだけを取得し、それ以外には何も取得しないことです。私は実用的な解決策から遠く離れているとは思いません。問題はおそらく、テンプレートの「一致」パラメーターに設定している値と、call-template with-param ノード内の選択パラメーターにあります。

どんな助けでも大歓迎です。

マイク

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 に答える