0

I am using ThumbGen to generate Movie Sheets. For my digital movies. It uses XSL. and my idea was to have it take the 'actors' and load the picture up from a folder with their pics in it. I searched online, and someone else had a question on how to fix an issue doing the exact same thing. So I used that as a basis, but was unable to get it to work.

I'm getting the error: "Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added."

In my trying to get this to work I found this:

https://social.msdn.microsoft.com/Forums/en-US/f83fa128-2d0d-4bdc-bfe1-26fbaf6159c7/xsl-and-xml-with-thumbgen

And using that, his 'fix' that was told to him, is giving me the error he was having before the fix, I've been working on it for the past week. but I've never even heard of XSL before this. Can anyone see maybe what's wrong with it?

But here is the Line in the XML File:

<ImageElement Name="Actor1" X="980" Y="44" Width="93" Height="123" Source="File" Offset="0" MultiPageIndex="-1" SourceData="" NullImageUrl="%PATH%\..\Common\cast\NoPhotoAvailable.jpg" />

Ok I've updated the XSL file To:

 <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>

And now i'm getting the error:

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)

Thank You. -Dev

Dev
  • 7
  • 4
  • Please post enough code (XML+XSLT) that would enable us to reproduce the problem. – michael.hor257k Nov 17 '14 at 15:12
  • that is all the XSL Code. I can post the full XML file. but since it's a template for ThumGen, I'd assume without ThumGen you wouldn't be able to reproduce it. – Dev Nov 17 '14 at 15:33

2 Answers2

0

You need to define template for attribute nodes, or the xslt processor will use the built-in one, which just output the attribute value as text node (see this previous post for details. Then, when you try to add an attribute to your element, you have several text nodes added previously by all the built-in templates on attributes.

So just add :

<xsl:template match="@*">
      <xsl:attribute name="{name()}" select="."/>
</xsl:template>

You could also just switch the <xsl:apply-templates select='@*'/> by :

<xsl:copy-of select="@*"/>

Which will do the job directly.

If you have more inputs elements, you may need to add a default template for elements too, a one like :

<xsl:template match="*">
    <xsl:copy>
        <xsl:apply-templates select='@* | node()'/>
    </xsl:copy>
</xsl:template>
Community
  • 1
  • 1
Eric S
  • 452
  • 4
  • 10
  • Thank You, I'm still a bit confused, I read that other link you posted as well. But in my attempts to get it to work it says: 'select' is an invalid attribute for the 'xsl:attribute' element. even with the second part added, and even with my apply-templates line changed to include select='@* | node()' as well. – Dev Nov 17 '14 at 15:55
  • Strange. Never checked in the specification before, but select seems not to be a regular attribute for xsl:attribute elements. I should use some lazy side of my processor. You could use copy-of then (edited my answer). – Eric S Nov 18 '14 at 08:25
0

i got it working with:

    <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>

Now i get to see if I make it work with more than actor.

Dev
  • 7
  • 4
  • How is this different from what you had to begin with? – michael.hor257k Nov 18 '14 at 01:04
  • You added the attribute template, but you should explicitely output the value of nodes or attributes as it's a bit confusing to use the built-in template implicetely on text values. An will do the job instead of a generic nested apply-templates. – Eric S Nov 18 '14 at 08:28