我正在尝试使用 XSLT 从文件制作器中以 xml 格式导出一些数据。我想在 xml 的三个位置显示相同的数据。我使用 for-each 标签显示了一次数据。一些如何在这里使用变量,但我不知道如何。
<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
<xsl:for-each select="fmp:COL[3]/fmpATA">
<marker>
<name>
<xsl:value-of select="."/>
</name>
<xsl:variable name="pos" select="position()" />
<comment>
<xsl:value-of select="../../fmp:COL[6]/fmpATA[$pos]"/>
</comment>
<in>
<xsl:value-of select="../../fmp:COL[4]/fmpATA[$pos]"/>
</in>
<out>
<xsl:value-of select="../../fmp:COL[5]/fmpATA[$pos]"/>
</out>
</marker>
</xsl:for-each>
</xsl:for-each>
但是当我想在同一个 XML 中的三个不同的地方导出上述数据时,它失败了。需要复制上述 xslt 中的任何数据,以便我可以在同一个 xslt 的其他地方使用它。我不是 XSLT 人,所以如果我不清楚,我一开始就道歉。非常感谢
输出:
<?xml version="1.0" encoding="UTF-8"?>
<xmeml version="1">
<sequence id="test_clip">
<name>test_clip</name>
<duration>7704</duration>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<timecode>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<string/>
<frame>90000</frame>
<source>source</source>
<displayformat>NDF</displayformat>
</timecode>
<in>-1</in>
<out>-1</out>
<media>
<video>
<format>
<samplecharacteristics>
<width>1024</width>
<height>576</height>
<anamorphic>FALSE</anamorphic>
<pixelaspectratio>Square</pixelaspectratio>
<fielddominance>none</fielddominance>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<colordepth>24</colordepth>
<codec>
<name>H.264</name>
<appspecificdata>
<appname>Final Cut Pro</appname>
<appmanufacturer>Apple Inc.</appmanufacturer>
<appversion>7.0</appversion>
<data>
<qtcodec>
<codecname>H.264</codecname>
<codectypename>H.264</codectypename>
<codectypecode>avc1</codectypecode>
<codecvendorcode>appl</codecvendorcode>
<spatialquality>1023</spatialquality>
<temporalquality>0</temporalquality>
<keyframerate>0</keyframerate>
<datarate>0</datarate>
</qtcodec>
</data>
</appspecificdata>
</codec>
</samplecharacteristics>
<appspecificdata>
<appname>Final Cut Pro</appname>
<appmanufacturer>Apple Inc.</appmanufacturer>
<appversion>7.0</appversion>
<data>
<fcpimageprocessing>
<useyuv>TRUE</useyuv>
<usesuperwhite>FALSE</usesuperwhite>
<rendermode>YUV8BPP</rendermode>
</fcpimageprocessing>
</data>
</appspecificdata>
</format>
<track>
<clipitem id="testclip3 ">
<name>testclip3</name>
<duration>7501</duration>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<in>0</in>
<out>7501</out>
<start>203</start>
<end>7704</end>
<pixelaspectratio>Square</pixelaspectratio>
<enabled>TRUE</enabled>
<anamorphic>FALSE</anamorphic>
<alphatype>none</alphatype>
<masterclipid>testclip3 1</masterclipid>
<logginginfo>
<good>FALSE</good>
</logginginfo>
<file id="testclip3 2">
<name>testclip3.mov</name>
<pathurl>file://localhost/Users/itsupport/Desktop/testclip3.mov</pathurl>
<rate>
<timebase>25</timebase>
</rate>
<duration>7501</duration>
<media>
<video>
<duration>7501</duration>
<samplecharacteristics>
<width>1024</width>
<height>576</height>
</samplecharacteristics>
</video>
<audio>
<rate>
<timebase>48000</timebase>
</rate>
<trackcount>2</trackcount>
<samplecharacteristics>
<depth>16</depth>
</samplecharacteristics>
</audio>
</media>
</file>
<marker>
<name>Marker 1</name>
<comment>Man uses lit lighter to read postcard and sets fire to it accidentally</comment>
<in>911814</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 2</name>
<comment>Painting</comment>
<in>913654</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 3</name>
<comment/>
<in>914031</in>
<out>914032</out>
</marker>
<marker>
<name>Marker 4</name>
<comment>Women</comment>
<in>925375</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 5</name>
<comment>Old woman</comment>
<in>932350</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 6</name>
<comment>car accident</comment>
<in>933750</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 7</name>
<comment/>
<in>900000</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 8</name>
<comment/>
<in>943925</in>
<out>-1</out>
</marker>
<sourcetrack>
<mediatype>video</mediatype>
</sourcetrack>
<link>
<linkclipref>testclip3 </linkclipref>
<mediatype>video</mediatype>
<trackindex>1</trackindex>
<clipindex>1</clipindex>
</link>
<link>
<linkclipref>testclip3 3</linkclipref>
<mediatype>audio</mediatype>
<trackindex>1</trackindex>
<clipindex>1</clipindex>
<groupindex>1</groupindex>
</link>
<link>
<linkclipref>testclip3 4</linkclipref>
<mediatype>audio</mediatype>
<trackindex>2</trackindex>
<clipindex>1</clipindex>
<groupindex>1</groupindex>
</link>
<fielddominance>none</fielddominance>
</clipitem>
<enabled>TRUE</enabled>
<locked>FALSE</locked>
</track>
</video>
<audio/>
</media>
<ismasterclip>FALSE</ismasterclip>
<marker>
<name>Marker 1</name>
<comment>Man uses lit lighter to read postcard and sets fire to it accidentally</comment>
<in>911814</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 2</name>
<comment>Painting</comment>
<in>913654</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 3</name>
<comment/>
<in>914031</in>
<out>914032</out>
</marker>
<marker>
<name>Marker 4</name>
<comment>Women</comment>
<in>925375</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 5</name>
<comment>Old woman</comment>
<in>932350</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 6</name>
<comment>car accident</comment>
<in>933750</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 7</name>
<comment/>
<in>900000</in>
<out>-1</out>
</marker>
<marker>
<name>Marker 8</name>
<comment/>
<in>943925</in>
<out>-1</out>
</marker>
<filter>
<effect>
<name>Distort</name>
<effectid>deformation</effectid>
<effectcategory>motion</effectcategory>
<effecttype>motion</effecttype>
<mediatype>video</mediatype>
<parameter>
<parameterid>aspect</parameterid>
<name>Aspect</name>
<valuemin>-10000</valuemin>
<valuemax>10000</valuemax>
<value>33.3333</value>
</parameter>
</effect>
</filter>
</sequence>
</xmeml>
您会注意到 marker1,2,3...8 标记在上面的 xml 中显示了两次。这就是我希望显示 xml 的方式。现在在 XSLT 中,请注意我已经复制了两次“for-each”标签。这不起作用。XSLT:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:fmp="http://www.filemaker.com/fmpxmlresult"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="fmp">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xmeml version="1">
<sequence id="test_clip">
<name>test_clip</name>
<duration>7704</duration>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<timecode>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<string><xsl:value-of select="fmp:COL[1]/fmp:DATA"/></string>
<frame>90000</frame>
<source>source</source>
<displayformat>NDF</displayformat>
</timecode>
<in>-1</in>
<out>-1</out>
<media>
<video><format>
<samplecharacteristics>
<width>1024</width>
<height>576</height>
<anamorphic>FALSE</anamorphic>
<pixelaspectratio>Square</pixelaspectratio>
<fielddominance>none</fielddominance>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<colordepth>24</colordepth>
<codec>
<name>H.264</name>
<appspecificdata>
<appname>Final Cut Pro</appname>
<appmanufacturer>Apple Inc.</appmanufacturer>
<appversion>7.0</appversion>
<data>
<qtcodec>
<codecname>H.264</codecname>
<codectypename>H.264</codectypename>
<codectypecode>avc1</codectypecode>
<codecvendorcode>appl</codecvendorcode>
<spatialquality>1023</spatialquality>
<temporalquality>0</temporalquality>
<keyframerate>0</keyframerate>
<datarate>0</datarate>
</qtcodec>
</data>
</appspecificdata>
</codec>
</samplecharacteristics>
<appspecificdata>
<appname>Final Cut Pro</appname>
<appmanufacturer>Apple Inc.</appmanufacturer>
<appversion>7.0</appversion>
<data>
<fcpimageprocessing>
<useyuv>TRUE</useyuv>
<usesuperwhite>FALSE</usesuperwhite>
<rendermode>YUV8BPP</rendermode>
</fcpimageprocessing>
</data>
</appspecificdata>
</format>
<track>
<clipitem id="testclip3 ">
<name>testclip3</name>
<duration>7501</duration>
<rate>
<ntsc>FALSE</ntsc>
<timebase>25</timebase>
</rate>
<in>0</in>
<out>7501</out>
<start>203</start>
<end>7704</end>
<pixelaspectratio>Square</pixelaspectratio>
<enabled>TRUE</enabled>
<anamorphic>FALSE</anamorphic>
<alphatype>none</alphatype>
<masterclipid>testclip3 1</masterclipid>
<logginginfo>
<good>FALSE</good>
</logginginfo>
<file id="testclip3 2">
<name>testclip3.mov</name>
<pathurl>file://localhost/Users/itsupport/Desktop/testclip3.mov</pathurl>
<rate>
<timebase>25</timebase>
</rate>
<duration>7501</duration>
<media>
<video>
<duration>7501</duration>
<samplecharacteristics>
<width>1024</width>
<height>576</height>
</samplecharacteristics>
</video>
<audio>
<rate>
<timebase>48000</timebase>
</rate>
<trackcount>2</trackcount>
<samplecharacteristics>
<depth>16</depth>
</samplecharacteristics>
</audio>
</media>
</file>
<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
<xsl:for-each select="fmp:COL[3]/fmp:DATA">
<marker>
<name>
<xsl:value-of select="."/>
</name>
<xsl:variable name="pos" select="position()" />
<comment>
<xsl:value-of select="../../fmp:COL[6]/fmp:DATA[$pos]"/>
</comment>
<in>
<xsl:value-of select="../../fmp:COL[4]/fmp:DATA[$pos]"/>
</in>
<out>
<xsl:value-of select="../../fmp:COL[5]/fmp:DATA[$pos]"/>
</out>
</marker>
</xsl:for-each>
</xsl:for-each>
<sourcetrack>
<mediatype>video</mediatype>
</sourcetrack>
<link>
<linkclipref>testclip3 </linkclipref>
<mediatype>video</mediatype>
<trackindex>1</trackindex>
<clipindex>1</clipindex>
</link>
<link>
<linkclipref>testclip3 3</linkclipref>
<mediatype>audio</mediatype>
<trackindex>1</trackindex>
<clipindex>1</clipindex>
<groupindex>1</groupindex>
</link>
<link>
<linkclipref>testclip3 4</linkclipref>
<mediatype>audio</mediatype>
<trackindex>2</trackindex>
<clipindex>1</clipindex>
<groupindex>1</groupindex>
</link>
<fielddominance>none</fielddominance>
</clipitem>
<enabled>TRUE</enabled>
<locked>FALSE</locked>
</track>
</video>
<audio></audio>
</media>
<ismasterclip>FALSE</ismasterclip>
<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
<xsl:for-each select="fmp:COL[3]/fmp:DATA">
<marker>
<name>
<xsl:value-of select="."/>
</name>
<xsl:variable name="pos" select="position()" />
<comment>
<xsl:value-of select="../../fmp:COL[6]/fmp:DATA[$pos]"/>
</comment>
<in>
<xsl:value-of select="../../fmp:COL[4]/fmp:DATA[$pos]"/>
</in>
<out>
<xsl:value-of select="../../fmp:COL[5]/fmp:DATA[$pos]"/>
</out>
</marker>
</xsl:for-each>
</xsl:for-each>
<filter>
<effect>
<name>Distort</name>
<effectid>deformation</effectid>
<effectcategory>motion</effectcategory>
<effecttype>motion</effecttype>
<mediatype>video</mediatype>
<parameter>
<parameterid>aspect</parameterid>
<name>Aspect</name>
<valuemin>-10000</valuemin>
<valuemax>10000</valuemax>
<value>33.3333</value>
</parameter>
</effect>
</filter>
</sequence>
</xmeml>
</xsl:template>
</xsl:stylesheet>