我正在尝试删除包含文本 PGS 的特定<SubtitleTrack>
分支<SubtitleType>
我想我快到了,但我不知道如何删除特定的字幕轨道分支。
这是我到目前为止所拥有的:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="SubtitleTracks">
<xsl:copy>
<xsl:choose>
<xsl:when test="SubtitleTrack/SourceTrack/SubtitleType=PGS">
[???]
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这是我正在使用的 XML:
<?xml version="1.0"?>
<ArrayOfQueueTask xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<QueueTask>
<IsNotifying>true</IsNotifying>
<ScannedSourcePath>E:TEMPMyVideo.mkv</ScannedSourcePath>
<Status>Waiting</Status>
<Task>
<IsNotifying>true</IsNotifying>
<ShowAdvancedTab>false</ShowAdvancedTab>
<SubtitleTracks>
<SubtitleTrack>
<IsNotifying>true</IsNotifying>
<Burned>false</Burned>
<Default>false</Default>
<Forced>false</Forced>
<SourceTrack>
<SourceId>7</SourceId>
<TrackNumber>1</TrackNumber>
<Language>English [PGS]</Language>
<LanguageCode>eng</LanguageCode>
<SubtitleType>PGS</SubtitleType>
</SourceTrack>
<SrtOffset>0</SrtOffset>
<SubtitleType>PGS</SubtitleType>
</SubtitleTrack>
<SubtitleTrack>
<IsNotifying>true</IsNotifying>
<Burned>false</Burned>
<Default>false</Default>
<Forced>false</Forced>
<SourceTrack>
<SourceId>4</SourceId>
<TrackNumber>2</TrackNumber>
<Language>English [UTF-8]</Language>
<LanguageCode>eng</LanguageCode>
<SubtitleType>UTF8Sub</SubtitleType>
</SourceTrack>
<SrtOffset>0</SrtOffset>
<SubtitleType>UTF8Sub</SubtitleType>
</SubtitleTrack>
</SubtitleTracks>
<Source>E:TEMPMyVideo.mkv</Source>
<Destination>C:TempOutputMyVideoEncode.mkv</Destination>
<OutputFormat>Mkv</OutputFormat>
<Grayscale>false</Grayscale>
<Rotation>0</Rotation>
<FlipVideo>false</FlipVideo>
<Sharpen>Off</Sharpen>
<SharpenPreset>
<DisplayName>Medium</DisplayName>
<Key>medium</Key>
</SharpenPreset>
<SharpenTune>
<DisplayName>None</DisplayName>
<Key>none</Key>
</SharpenTune>
<SharpenCustom />
<VideoEncodeRateType>ConstantQuality</VideoEncodeRateType>
<VideoEncoder>X264</VideoEncoder>
<FramerateMode>VFR</FramerateMode>
<Quality>19</Quality>
<VideoBitrate xsi:nil="true" />
<TwoPass>true</TwoPass>
<TurboFirstPass>false</TurboFirstPass>
<Framerate xsi:nil="true" />
</QueueTask>
</ArrayOfQueueTask>
感谢您的任何帮助
您可以简单地使用谓词直接匹配要删除的元素,并通过空模板处理它们:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="SubtitleTrack[SourceTrack/SubtitleType='PGS']"/>
</xsl:stylesheet>
或者一开始就不对它们应用模板:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="SubtitleTracks">
<xsl:copy>
<xsl:apply-templates select="*[not(self::SubtitleTrack[SourceTrack/SubtitleType='PGS'])]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
缺少结束标记任务的源 xml
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="SubtitleTrack">
<xsl:choose>
<xsl:when test="SourceTrack[not(contains(SubtitleType,'PGS'))]">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
only change following code:-
<xsl:when test="SubtitleTrack/SourceTrack/SubtitleType='PGS'">