none
xsl and xml with thumbgen

    Question

  • I have very little knowledge of xml or xsl sheets. I have been experimenting with a program called Thumbgen to generate movie graphics with pictures of actors. The movie data is 'scraped' by Thumbgen and can then be manipulated by a style sheet and/or an xml document. This first section is a bit of the style sheet where actors names areextracted from a string of names separated by "/" symbols


     <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, '/')" />  

    This second bit is further down the style sheet where the actor image related to the actor name is found in a folder full of jpg's



     <xsl:template match="ImageElement[@Name='Actor1']">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
                <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:copy>
        </xsl:template>


    This is a small bit of the xml sheet where the actor jpg is 'placed' in a larger jpg (1280 x 720)


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

     <Actions>
              <Rotate Angle="3" InterpolationMode="HighQualityBicubic" />
            </Actions>

    Everything works fine except if I add the last bit - the rotate angle action. When I do that it produces an error message:
    "Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added." Is there any way around this problem?
    Saturday, June 30, 2012 10:28 PM

All replies

  • I think you simply want to change the order of some of your code i.e. change

    <xsl:template match="ImageElement[@Name='Actor1']">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
                <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:copy>
        </xsl:template>
    

    to

    <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>
    
    That way the attributes are created first, then all child elements while with your current code it can happen that some child elements are created and then later on an attempt to add an attribute 'SourceData' is made which fails.


    MVP Data Platform Development My blog

    • Proposed as answer by Martin Honnen Sunday, July 1, 2012 10:41 AM
    Sunday, July 1, 2012 10:34 AM
  • Brilliant Martin :) your blood's worth bottling :)
    Sunday, July 1, 2012 1:07 PM