1

これは、XSL を使用して XML から XML に拡張されます 問題 私は exslt をインポートし、次のように与えられた解決策 (Kyle Butt に感謝) に従ってコードを修正しました:

<xsl:stylesheet version="1.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:func="http://exslt.org/functions"
              xmlns:set="http://exslt.org/sets"
              extension-element-prefixes="set">

<xsl:import href="set.distinct.function.xsl"/>

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

<xsl:template match="gallery">
  <gallery>
    <xsl:variable name="gallery" select="."/>
    <xsl:for-each select="set:distinct(photo/tag/event)">
      <xsl:value-of select="."/>
      <event name="{.}">
        <xsl:variable name="event" select="." />
        <xsl:for-each select="set:distinct($gallery/object/tag[event=.]/group)">
          <group name="{.}">
            <xsl:variable name="group" select="." />
            <xsl:apply-templates select="$gallery/object[tag/event=$event][tag/group=$group]" />
          </group>
        </xsl:for-each>
      </event>
    </xsl:for-each>
  </gallery>
</xsl:template>

しかし、出力に「Function set:distinct() has failed.」というエラーが表示されます。値を null にすることはできません。これを解決するには?

ところでXML入力:

<gallery>
  <photo>
    <tag>
      <event>Birthday</event>
      <group>Family</group>
      <other>Swensens</other>
    </tag>
  </photo>
  <photo>..</photo>
</gallery>

& 必要な XML 出力:

<gallery>
  <event name="Birthday">
    <group name="Family">
      <photo>
        <tag>
         <other>Swensens</other>
        </tag>
      </photo>
      <photo>..</photo>
    </group>
    <group>..</group>
  </event>
  <event>..</event>
</gallery>
4

1 に答える 1