xsl-list
[Top] [All Lists]

Re: How adress what might be attribute or element?

2006-01-18 06:04:29

Can I put two <xsl:value-of select /> statements in each variable? 
You can put any number of xsl constructs there, but in fact you don't
really want any xsl:value-of here.

         <xsl:variable name="xresolution">
                                <xsl:value-of 
select="/x:xmpmeta/rdf:RDF/rdf:Description/tiff:XResolution" />
                            </xsl:variable>

don't use xsl:variable with content unless you need to, it creates a
result tree fragment (or temporary tree in xslt2) when you just need to
select the element directly
<xsl:variable name="xresolution"
select="/x:xmpmeta/rdf:RDF/rdf:Description/tiff:XResolution">

You could write

                     <xsl:value-of 
select="/x:xmpmeta/rdf:RDF/rdf:Description/@tiff:ImageWidth" /> 
                    <xsl:value-of 
select="/x:xmpmeta/rdf:RDF/rdf:Description/tiff:ImageWidth" />

as
    <xsl:value-of
    select="/x:xmpmeta/rdf:RDF/rdf:Description/@tiff:ImageWidth
   |
/x:xmpmeta/rdf:RDF/rdf:Description/tiff:ImageWidth
" /> 

But that doesn't really look any nicer. if you are using XSLT2 you could
write


  <xsl:value-of
    
select="/x:xmpmeta/rdf:RDF/rdf:Description/(tiff:ImageWidth|@tiff:ImageWidth)
" /> 

Or In XSLT1 I'd probably change the current node, and write

<xsl:for-each select="/x:xmpmeta/rdf:RDF/rdf:Description">
 <xsl:value-of select="tiff:ImageWidth|@tiff:ImageWidth"/>
</xsl:for-each>

(But if you use for-each  in the cases where you use variables, you would have
to use the content of the variable rather than a select attribute.)

If I was doing this in xslt2 I'd probably write a function

<xsl:function name="f:property" as="xs:string">
 <xsl:param name="x" as="xs:string"/>
 <xsl:sequence select="string((@*|*)[local-name()=$x][1])"/>
</xsl:function>

used as
<xsl:value-of
    select="/x:xmpmeta/rdf:RDF/rdf:Description/f:property('ImageWidth')"/>

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>