Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1171
  • Last Modified:

XSL - For-Each Show first, hide others

<xsl:for-each select="//results/errorpages/page[@error = $errorID]">
 <xsl:variable name="errorpageid" select="."/>
 <xsl:if test="count(//results/page[@id = $errorpageid and @error = $errorID]) > 0">
   <div class="row{position() mod 2}">
   <xsl:variable name="cHider"><xsl:value-of select="generate-id()"/></xsl:variable>
   <xsl:for-each select="//results/page[@id = $errorpageid and @error = $errorID]">

   'RIGHT HERE I WANNA DISPLAY THE TITLE OF THE FIRST ONE AND ALL INCLUDING THE FIRST ONE BE IN A HIDDEN DIV TAG. BELOW IT.. BASICALLY A <XSL:IF TEST="POSITION() = 1">SHOW TITLE</XSL:IF>
   'HERE IS WHERE I AM STUMPED, I WANT 1 <DIV STYLE="DISPLAY:NONE"> ... THE REST OF THE ITEMS... THEN </DIV>
   </xsl:for-each>
  </div>
 </xsl:if>
</xsl:for-each>

Sorry about the caps, I would go back but I will jsut appologize cause Im too lazy to re-write it :)

0
B_Dorsey
Asked:
B_Dorsey
  • 4
1 Solution
 
Geert BormansCommented:
well, well, I am not sure I understand the question completely

If you want to add a div tag around all the items of the for-each, just do it outside the loop
Can you be a bit more specific in your question
show a small piece of the XML and the result yo want

thanks

Geert
0
 
Geert BormansCommented:
maybe this is what you are looking for
I have an example outside the context of your example, but simplified

<?xml version="1.0" encoding="UTF-8"?>
<example>
    <item>
        <title>AAA</title>
        <note>A1</note>
    </item>
    <item>
        <title>BBB</title>
        <note>B1</note>
    </item>
    <item>
        <title>CCC</title>
        <note>C1</note>
    </item>
</example>

and the stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="example">
        <div style="display:none;">
            <title><xsl:value-of select="item[1]/title"/></title>
            <xsl:for-each select="item">
                <p><xsl:value-of select="note"/></p>
            </xsl:for-each>
        </div>
    </xsl:template>
</xsl:stylesheet>


0
 
Geert BormansCommented:
If you don't need the first item in the iteration, you can do like this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="example">
        <div style="display:none;">
            <title><xsl:value-of select="item[1]/title"/></title>
            <xsl:for-each select="item[position() &gt;= 2]">
                <p><xsl:value-of select="note"/></p>
            </xsl:for-each>
        </div>
    </xsl:template>
</xsl:stylesheet>

0
 
B_DorseyAuthor Commented:
To the rescue again... thanks again.
0
 
Geert BormansCommented:
welcome
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now