Trouble choosing value
This is an open discussion with 3 replies, filed under XSLT.
Search
What’s the context of your xsl template: what’s your current node when selecting substring-after(., '/posts/')
?
forget the exact context, but in this scenario, we’ll say it does evaluate to a value (which it does in the real one). But since I’m using //post-images
, the context doesn’t really matter. I think i’m narrowing down the issue, though. It seems like it’s only happening on posts that have just one image in it. Haven’t finished my testing though.
ha…so i wasn’t going crazy - turned out it was the wrong freaking image! testing things out and one image got uploaded twice, but at different times. so with the unique upload field extension, it got me confused for a very long time!
anyway, that above does work, but here’s a more succinct way of writing it:
<xsl:param name="w"> <xsl:choose> <xsl:when test="$img-val = //post-images/post[@link-id = $entry]/entry/image/filename"> <xsl:value-of select="//post-images/post[@link-id = $entry]/entry[image/filename = $img-val]/width" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="450" /> </xsl:otherwise> </xsl:choose> </xsl:param>
this is assuming there is a width
(and height
if you choose so) field(s) available when an image is uploaded and the correct content is attached to the DS. This method, which was modified from my JIT image formatter utility, in turn allows for dynamic resizing images within a blog post!
edit: to make this even more generic, it can be written like this instead:
<xsl:param name="w"> <xsl:choose> <xsl:when test="$img-val = //post-images/post/entry/image/filename"> <xsl:value-of select="//post-images/post/entry[image/filename = $img-val]/width" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="450" /> </xsl:otherwise> </xsl:choose> </xsl:param>
the [@link-id = $entry]
was unnecessary. by writing it this way, it will work on a list of blog posts as well as individual ones.
Create an account or sign in to comment.
I am trying to get some width/height values based on an image src value. I currently have this xml:
and i want to select the
width
andheight
that are a child of theentry
. I tried this xsl:but this line:
that does not match anything - it comes back as false so it grabs the default value. When i remove
$img-val =
, that statement:works and so it grabs my correct width value.
Does anyone know why i cannot do a
test
two different values in this manner?