ここでいくつかのコードを見つけましたが、これは良いスタートですが、探しているものとは少し異なり、続行する方法がわかりません。私がやりたいことは、XML ファイル全体をコピーし、複数の区切り記号に基づいて Author 要素を分割して新しい要素を作成し、元の「Author」要素名を削除することです。各作成者の「セット」はセミコロンで区切られ、キャリッジ リターンまたはレコード 4 のように単なるキャリッジ リターンで終わります。私は XSLT の初心者であり、ソリューションを機能させるだけでなく理解したいので、提供されたソリューションの説明は素晴らしいでしょう。ありがとう。
コード:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:e="http://localhost">
<xsl:output indent="yes"/>
<e:e>AuthorName</e:e>
<e:e>AuthorLocation</e:e>
<e:e>AuthorPhone</e:e>
<xsl:variable name="vElement" select="document('')/*/e:*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Author/text()" name="tokenizer">
<xsl:param name="pString" select="string()"/>
<xsl:param name="pPosition" select="1"/>
<xsl:if test="$pString">
<xsl:element name="{$vElement[$pPosition]}">
<xsl:value-of select="normalize-space(substring-before(concat($pString,';'),';'))"/>
</xsl:element>
<xsl:call-template name="tokenizer">
<xsl:with-param name="pString" select="substring-after($pString,';')"/>
<xsl:with-param name="pPosition" select="$pPosition + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
XML ファイル
<RECORD_SET>
<RECORD NUM="1">
<Title>Title1</Title>
<Author>Author Name 1; Author Location 1; Author Phone Number 1</Author>
<Date>11/20/1976</Date>
</RECORD>
<RECORD NUM="2">
<Title>Title2</Title>
<Author>Author Name 2; Author Location 2; Author Phone Number 2
Author Name 3; Author Location 3; Author Phone Number 3
Author Name 4; Author Location 4; Author Phone Number 4</Author>
<Date>10/20/2001</Date>
</RECORD>
<RECORD NUM="3">
<Title>Title3</Title>
<Author>Author Name 5; Author Location 5; Author Phone Number 5
Author Name 6; Author Location 6; Author Phone Number 6</Author>
<Date>09/18/1966</Date>
</RECORD>
<RECORD NUM="4">
<Title>Title4</Title>
<Author>Author Name 7
Author Name 8</Author>
<Date>01/18/1956</Date>
</RECORD>
</RECORD_SET>
望ましい出力
<RECORD_SET>
<RECORD NUM="1">
<Title>Title1</Title>
<AuthorName>Author Name 1</Author>
<AuthorLocation>Author Location 1</AuthorLocation>
<AuthorPhone>Author Phone Number 1</AuthorPhone>
<Date>11/20/1976</Date>
</RECORD>
<RECORD NUM="2">
<Title>Title2</Title>
<AuthorName>Author Name 2</Author>
<AuthorLocation>Author Location 2</AuthorLocation>
<AuthorPhone>Author Phone Number 2</AuthorPhone>
<AuthorName>Author Name 3</Author>
<AuthorLocation>Author Location 3</AuthorLocation>
<AuthorPhone>Author Phone Number 3</AuthorPhone>
<AuthorName>Author Name 4</Author>
<AuthorLocation>Author Location 4</AuthorLocation>
<AuthorPhone>Author Phone Number 4</AuthorPhone>
<Date>10/20/2001</Date>
</RECORD>
<RECORD NUM="3">
<Title>Title3</Title>
<AuthorName>Author Name 5</Author>
<AuthorLocation>Author Location 5</AuthorLocation>
<AuthorPhone>Author Phone Number 5</AuthorPhone>
<AuthorName>Author Name 6</Author>
<AuthorLocation>Author Location 6</AuthorLocation>
<AuthorPhone>Author Phone Number 6</AuthorPhone>
<Date>09/18/1966</Date>
</RECORD>
<RECORD NUM="4">
<Title>Title4</Title>
<AuthorName>Author Name 7</AuthorName>
<AuthorName>Author Name 8</AuthorName>
<Date>01/18/1956</Date>
</RECORD>
</RECORD_SET>
電流出力
<RECORD NUM="1">
<Title>Title1</Title>
<Author>
<AuthorName>Author Name 1</AuthorName>
<AuthorLocation>Author Location 1</AuthorLocation>
<AuthorPhone>Author Phone Number 1</AuthorPhone>
</Author>
<Date>11/20/1976</Date>
</RECORD>
<RECORD NUM="2">
<Title>Title2</Title>
<Author>
<AuthorName>Author Name 2</AuthorName>
<AuthorLocation>Author Location 2</AuthorLocation>
<AuthorPhone>Author Phone Number 2 Author Name 3</AuthorPhone>Author Location 3Author Phone Number 3 Author Name 4Author Location 4Author Phone Number 4
</Author>
<Date>10/20/2001</Date>
</RECORD>
<RECORD NUM="3">
<Title>Title3</Title>
<Author>
<AuthorName>Author Name 5</AuthorName>
<AuthorLocation>Author Location 5</AuthorLocation>
<AuthorPhone>Author Phone Number 5 Author Name 6</AuthorPhone>Author Location 6Author Phone Number 6
</Author>
<Date>09/18/1966</Date>
</RECORD>
<RECORD NUM="4">
<Title>Title4</Title>
<Author>
<AuthorName>Author Name 7 Author Name 8</AuthorName>
</Author>
<Date>01/18/1956</Date>
</RECORD>