Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm using a checkboxlist which contains the followings node values
1110, 1111, 1112, 1113
what would be the best way with xslt do extract a single node value
ie i want to display all content that has a value of '1111'
hmm, maybe i haven't explain my question very well. So when you use a datatype that give you multiple option
ie checkbox list or a list box. How do you work with these values in xslt. As you get an array
so how would i do a foreach and just get '1110'
Hi Anthony,
You can use the Split method from the umbraco.library, like this:
<xsl:variable name="nodeIds" select="umbraco.library:Split('1110,1111,1112,1113', ',')" /> <xsl:for-each select="$nodeIds/value"> <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)"/> <a href="{umbraco.library:NiceUrl($node/@id)}"> <xsl:value-of select="$node/@nodeName" /> </a> </xsl:for-each>
Inside the for-each loop, you can extract whatever page data that you want.
I did it like this:
<xsl:variable name="categories" select="umbraco.library:Split($currentPage/data [@alias = 'categories'], ',')" /> <xsl:for-each select="$categories/value"> <xsl:if test=". = 1151"> Do something </xsl:if> </xsl:for-each>
Ha, I was too slow in writing my code, and Lee's is even better ;-)
No worries Sebastiaan, it's the same concept - great minds think alike!
I may be misinterpreting this, but to get all nodes that contain 1110, then you would use contains....
$nodesToFilter[contains(data[@alias='categories'],'1110')]
note that you may want to concatenate commas around both parameters, as 1110 will match 1110, as well as 11110 and 11100-9, etc. Not a problem on small sites, but, I have some sites with ids that high.
$nodesToFilter[contains(concat(',',data[@alias='categories'],','),concat(',','1110',','))]
thanks really appreciate the response, actually learn alot thru these answers. I've gone with casey's 'contain' method.
here's what i've got. Any thoughts on how i could add the if statement to the foreach,
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle']"><xsl:if test="contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">// content here. </xsl:if></xsl:for-each>
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle']">
<xsl:if test="contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">
// content here.
</xsl:if>
</xsl:for-each>
This should work:
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">...</xsl:for-each>
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">
...
Oops, missing a "]" at the end there, so:
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))]">...</xsl:for-each>
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))]">
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
extract node value from array
I'm using a checkboxlist which contains the followings node values
1110, 1111, 1112, 1113
what would be the best way with xslt do extract a single node value
ie i want to display all content that has a value of '1111'
hmm, maybe i haven't explain my question very well. So when you use a datatype that give you multiple option
ie checkbox list or a list box. How do you work with these values in xslt. As you get an array
1110, 1111, 1112, 1113
so how would i do a foreach and just get '1110'
Hi Anthony,
You can use the Split method from the umbraco.library, like this:
Inside the for-each loop, you can extract whatever page data that you want.
I did it like this:
Ha, I was too slow in writing my code, and Lee's is even better ;-)
No worries Sebastiaan, it's the same concept - great minds think alike!
I may be misinterpreting this, but to get all nodes that contain 1110, then you would use contains....
note that you may want to concatenate commas around both parameters, as 1110 will match 1110, as well as 11110 and 11100-9, etc. Not a problem on small sites, but, I have some sites with ids that high.
thanks really appreciate the response, actually learn alot thru these answers. I've gone with casey's 'contain' method.
here's what i've got. Any thoughts on how i could add the if statement to the foreach,
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle']">
<xsl:if test="contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">
// content here.
</xsl:if>
</xsl:for-each>
This should work:
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))">
...
</xsl:for-each>
Oops, missing a "]" at the end there, so:
<xsl:for-each select="$home/descendant::node [@nodeTypeAlias = 'productStyle' and contains(concat(',',data[@alias='productStyleCategories'],','),concat(',',$categoryId,','))]">
...
</xsl:for-each>
is working on a reply...