我正在使用ThumbGen生成电影表。对于我的数字电影。它使用XSL。而我的想法是让这些演员'并从包含照片的文件夹中加载图片。我在网上搜索,其他人有一个问题,如何解决问题做同样的事情。所以我用它作为基础,但无法让它发挥作用。
我收到错误: "在添加了text,comment,pi或子元素节点之后,无法将属性和命名空间节点添加到父元素。"
在我试图让这个工作时,我发现了这个:
使用它,他的修复'有人告诉他,在给我修复之前他给我的错误,过去一周我一直在研究它。但在此之前我从未听说过XSL。任何人都可以看到它可能有什么问题吗?
但这是XML文件中的行:
<ImageElement Name="Actor1" X="980" Y="44" Width="93" Height="123" Source="File" Offset="0" MultiPageIndex="-1" SourceData="" NullImageUrl="%PATH%\..\Common\cast\NoPhotoAvailable.jpg" />
好的我已将XSL文件更新为:
<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:variable name="pathvalue" select="//tokens/token[@name='%PATH%']"/>
<xsl:variable name="folderactors" select="string('\..\Common\cast\')"/>
<xsl:variable name="actorsext" select="string('.jpg')"/>
<xsl:variable name="actorstext" select="string('')"/>
<xsl:variable name="lista1" select="//tokens/token[@name='%ACTORS%']"/>
<xsl:variable name="actor1" select="substring-before($lista1, ',')" />
<xsl:variable name="resto1" select="substring-after($lista1, ',')" />
<xsl:variable name="lista2" select="$resto1"/>
<xsl:variable name="actor2" select="substring-before($lista2, ',')" />
<xsl:template match="ImageElement[@Name='Actor1']">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:choose>
<xsl:when test="$actor1 != '' ">
<xsl:attribute name="SourceData">
<xsl:value-of select="concat($pathvalue,$folderactors,$actor1,$actorsext)"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
现在我收到了错误:
1: 2014-11-17 09:18:00.1842 [RenderMoviesheet] Entering rendermoviesheet
1: 2014-11-17 09:18:00.1842 [RenderMoviesheet] Needs render
1: 2014-11-17 09:18:00.1842 [RenderMoviesheet] Start analyze template
1: 2014-11-17 09:18:00.5332 [RenderMoviesheet] End analyze template
1: 2014-11-17 09:18:01.2673 [RenderMoviesheet] Rendering using Clear Showcase;
thumbmode=True; done in 732.0419ms; file= filename.avi
1: 2014-11-17 09:18:01.2673 [RenderMoviesheet] Saving small preview
1: 2014-11-17 09:18:01.2733 [CreateThumbnailImage] Resizing C:\Users\Dev\AppData\Local\Temp\_thumbgen_tmp\171b3083-e6b7-4ec9-9ea2-1b54b8a8c14d.jpg to C:\Users\Dev\AppData\Local\Temp\_thumbgen_tmp\633c815b-afe3-432c-ba27-a7fb90c43f7f.jpg
1: 2014-11-17 09:18:01.3173 [RenderMoviesheet] Small preview saved
1: 2014-11-17 09:18:03.3764 [RenderMoviesheet] Entering rendermoviesheet
1: 2014-11-17 09:18:03.3774 [RenderMoviesheet] Needs render
1: 2014-11-17 09:18:03.3774 [RenderMoviesheet] Start analyze template
1: 2014-11-17 09:18:03.7614 [RenderMoviesheet] End analyze template
1: 2014-11-17 09:18:03.7614 [RenderMoviesheet] XSL Found
1: 2014-11-17 09:18:03.8174 [RenderMoviesheet] XSL Processed
1: 2014-11-17 09:18:03.8174 [RenderMoviesheet] Exception loading template:Invalid XML data for restoring ImageDraw object.
<?xml version="1.0" encoding="utf-8"?>
<ImageElement Name="" X="" Y="" Width="" Height="" Source="" Offset="" MultiPageIndex="" NullImageUrl="" SourceData="C:\Users\Dev\Desktop\ThumGen\Templates\Clemery's Ultimate MOVIE SHEET\..\Common\cast\Nicole Kidman.jpg" />
1: 2014-11-17 09:18:03.8174 [RenderMoviesheet] render System.Exception: Invalid XML data for restoring ImageDraw object.
at ThumbGen.MovieSheets.MovieSheetsGenerator.RenderMoviesheet(Boolean getThumbnail)
谢谢。 -dev
答案 0 :(得分:0)
您需要为属性节点定义模板,否则xslt处理器将使用内置的模板,只需将属性值输出为文本节点(see this previous post for details。然后,当您尝试添加属性时在您的元素中,您有多个文本节点先前由属性上的所有内置模板添加。
所以只需添加:
<xsl:template match="@*">
<xsl:attribute name="{name()}" select="."/>
</xsl:template>
您也可以通过以下方式切换<xsl:apply-templates select='@*'/>
:
<xsl:copy-of select="@*"/>
将直接完成这项工作。
如果你有更多的输入元素,你可能还需要为元素添加一个默认模板,如:
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select='@* | node()'/>
</xsl:copy>
</xsl:template>
答案 1 :(得分:0)
我得到了它:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ImageElement[@Name='Actor1']">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:choose>
<xsl:when test="$actor1 != '' ">
<xsl:attribute name="SourceData">
<xsl:value-of select="concat($pathvalue,$folderactors,$actor1,$actorsext)"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
现在我开始看看我是否让它比演员更有效。