Avatar billede den-evil Nybegynder
17. juni 2008 - 13:24 Der er 9 kommentarer

Paging med XSLT?

Jeg har noget XML der ser sådanne ud

    <Documents>
            <Document Id="23057">
                <Name>Test Nyhed 1</Name>
                <DocumentEdition>
                    <Fields>
                        <Field Name="Heading" FieldType="SingleLineText">Det nye skuespillerhus har fået lofter fra Gyptone</Field>
                        <Field Name="Image01" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/billed1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image01Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="Image02" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/newslist1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image02Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="NewsPublishingScope" FieldType="CheckBoxGroup">
                            <Option Name="GyprocHomepage"/>
                            <Option Name="GyptoneHomepage">showOnGyptoneHomepage</Option>
                            <Option Name="DIYHomepage"/>
                            <Option Name="ProductHomepage"/>
                        </Field>
                        <Field Name="Text" FieldType="VisualEditor">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</Field>
                    </Fields>
                </DocumentEdition>
            </Document>
            <Document Id="23058">
                <Name>Test Nyhed 2</Name>
                <DocumentEdition>
                    <Fields>
                        <Field Name="Heading" FieldType="SingleLineText">Nyt website til Gyptone</Field>
                        <Field Name="Image01" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/billed1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image01Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="Image02" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/newslist1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image02Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="NewsPublishingScope" FieldType="CheckBoxGroup">
                            <Option Name="GyprocHomepage"/>
                            <Option Name="GyptoneHomepage">showOnGyptoneHomepage</Option>
                            <Option Name="DIYHomepage"/>
                            <Option Name="ProductHomepage"/>
                        </Field>
                        <Field Name="Text" FieldType="VisualEditor">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</Field>
                    </Fields>
                </DocumentEdition>
            </Document>
            <Document Id="23059">
                <Name>Test Nyhed 3</Name>
                <DocumentEdition>
                    <Fields>
                        <Field Name="Heading" FieldType="SingleLineText">HLA Architects udvider med Gyptone Kontorer</Field>
                        <Field Name="Image01" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/billed1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image01Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="Image02" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/newslist1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image02Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="NewsPublishingScope" FieldType="CheckBoxGroup">
                            <Option Name="GyprocHomepage"/>
                            <Option Name="GyptoneHomepage">showOnGyptoneHomepage</Option>
                            <Option Name="DIYHomepage"/>
                            <Option Name="ProductHomepage"/>
                        </Field>
                        <Field Name="Text" FieldType="VisualEditor">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</Field>
                    </Fields>
                </DocumentEdition>
            </Document>
            <Document Id="23060">
                <Name>Test Nyhed 4</Name>
                <DocumentEdition>
                    <Fields>
                        <Field Name="Heading" FieldType="SingleLineText">Gyptones inspirations håndbog er på gaden</Field>
                        <Field Name="Image01" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/billed1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image01Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="Image02" FieldType="Media">&amp;lt;img alt="" src="/files/Design/Gyptone/images/underside/newslist1.jpg" style="" /&amp;gt;</Field>
                        <Field Name="Image02Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="NewsPublishingScope" FieldType="CheckBoxGroup">
                            <Option Name="GyprocHomepage"/>
                            <Option Name="GyptoneHomepage">showOnGyptoneHomepage</Option>
                            <Option Name="DIYHomepage"/>
                            <Option Name="ProductHomepage"/>
                        </Field>
                        <Field Name="Text" FieldType="VisualEditor">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</Field>
                    </Fields>
                </DocumentEdition>
            </Document>
            <Document Id="23522">
                <Name>Test Nyhed 5</Name>
                <DocumentEdition>
                    <Fields>
                        <Field Name="Heading" FieldType="SingleLineText">555</Field>
                        <Field Name="Image01" FieldType="Media"/>
                        <Field Name="Image01Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="Image02" FieldType="Media"/>
                        <Field Name="Image02Placement" FieldType="RadioButtonGroup">right</Field>
                        <Field Name="NewsPublishingScope" FieldType="CheckBoxGroup">
                            <Option Name="GyprocHomepage"/>
                            <Option Name="GyptoneHomepage">showOnGyptoneHomepage</Option>
                            <Option Name="DIYHomepage"/>
                            <Option Name="ProductHomepage"/>
                        </Field>
                        <Field Name="Text" FieldType="VisualEditor">Lorem ipsum</Field>
                    </Fields>
                </DocumentEdition>
            </Document>
        </Documents>

-----------------------------

Har bare ingen idé om hvordan jeg laver paging på dette, max 3 indlæg pr side???
Avatar billede den-evil Nybegynder
17. juni 2008 - 14:16 #1
jeg har prøvet dette, uden held:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" encoding="UTF-8"/>

  <xsl:template match="Documents">

      <xsl:apply-templates select="Document"/>
        <xsl:apply-templates select="recursive"/>
   
  </xsl:template>

    <xsl:template name="recursive">
    <xsl:param name="start"/>
    <xsl:param name="end"/>
    <xsl:variable name="Docs" select="Document[position() > $start and $end >= position()]" />
    <xsl:if test="count($Docs) > 0">
    <xsl:call-template name="recursive">
    <xsl:with-param name="start" select="$end" />
    <xsl:with-param name="end" select="$end + 1" />
    </xsl:call-template>
    </xsl:if>
    </xsl:template>

  <xsl:template match="Document">
  <div class="newsitem">
        <div class="newsheader">
            <a href="via24960.html?id={@Id}">
                <strong><xsl:value-of select="DocumentEdition/Fields/Field[@Name='Heading']"/></strong>
            </a>
        </div>
        <div class="newslist">
            <xsl:if test="DocumentEdition/Fields/Field[@Name='Image02'] !=''">
                <div class="newslist_pict{DocumentEdition/Fields/Field[@Name = 'Image02Placement']}">
                    <xsl:value-of select="DocumentEdition/Fields/Field[@Name='Image02']" disable-output-escaping="yes"/>
                </div>
            </xsl:if>
            <xsl:apply-templates select="DocumentEdition/Fields/Field[@Name='Text']"/>
        </div>
        <div class="reset">&#160;</div>
    </div>
    <hr style="height: 1px; overflow: hidden;" />
  </xsl:template>
 
  <xsl:template match="/Module">
    <xsl:apply-templates select="//Row"/>
  </xsl:template>

  <xsl:template match="Row">
    <xsl:apply-templates select="Cell"/>
  </xsl:template>

  <xsl:template match="Cell">
    <xsl:value-of disable-output-escaping="yes" select="ContentArea"/>
  </xsl:template>

    <xsl:template match="Field[@Name='Text']">
            <xsl:value-of select="substring(.,1,200)" />
            <xsl:if test="string-length(.) &gt; 200">...</xsl:if>
            <!--xsl:copy-of select="* | text()"/-->
    </xsl:template>

  <xsl:template match="RequestContent"/>

</xsl:stylesheet>
Avatar billede jokkejensen Novice
17. juni 2008 - 15:08 #2
arbejder du hos dynamic ? vh
Avatar billede jokkejensen Novice
17. juni 2008 - 16:05 #3
Men, start med at tælle hvor mange dokumenter du har,

Psuedo:

//Tæller antal
$count  = count(Documents//Document)
//Henter side nr ud fra querystring, ellers 1.
$page = <xsl:if test="RequestContent/QueryString/Entry[Name='Page']"><xsl:value-of select="RequestContent/QueryString/Entry[Name='Page']"></xsl:if><xsl:if test="not (RequestContent/QueryString/Entry[Name='Page'])">1</xsl:if>
//Antal nyheder
$MaxCount = 3

//Skjules/Vises alt efter maxcount og count
<a href="?Page={$page+1}">næste</a>
<a href="?Page={$page-1}">forrige</a>

Hvis du så vil køre dem med position, noget ala:

<xsl:template match="Document[(position() < ($page * $maxcount)) and (position() > (($page * $maxcount) - ($maxcount-1)))) ]">

Så skulle den gerne ex på side 2 skrive:

<xsl:template match="Document[(position() < (2 * 3)) and (position() > ((2 * 3) - (2)))) ]">

Altså vise 4, 5, 6.

Venligst.
Jacob
Avatar billede den-evil Nybegynder
18. juni 2008 - 09:15 #4
Ok, jeg kom selv frem til dette, men er ligesom gået lidt fast - Vil gerne have den til at skrive 1-2-3-4-5-6-7-8 ->    <--- Antal sider og pilen er næste side)


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:user="urn:my-scripts">
    <xsl:output omit-xml-declaration="yes" encoding="UTF-8"/>
    <xsl:variable name="startpos">
        <xsl:choose>
            <xsl:when test="//RequestContent/QueryString/Entry[@Name='page']"><xsl:value-of select="//RequestContent/QueryString/Entry[@Name='page']" /></xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="perpage" select="'5'"/>
    <xsl:variable name="doctotal" select="count(//Document)"/>
    <xsl:template match="Documents">
        <xsl:value-of select="$startpos"/>
        <xsl:value-of select="$perpage"/>
        <xsl:for-each select="Document[position() &gt;= $startpos and position() &lt; ($startpos+$perpage)]">
            <!--xsl:if test="position() &gt; $startpos and position() &lt; ($startpos+$perpage)"-->
            <xsl:call-template name="mintemplate"/>
            <br/>
            <!--/xsl:if-->
        </xsl:for-each>
        <div class="paging">
            Side: <xsl:value-of select="$startpos" /> af <xsl:value-of select="ceiling($doctotal div $perpage)" />
            <!--<xsl:for-each select="Document[position() &gt;= $startpos and position() &lt; ($startpos+$perpage)]">
                hej
            </xsl:for-each>-->
        </div>
        <!--xsl:apply-templates select="Document"/-->
    </xsl:template>
   
    <xsl:template name="mintemplate">
        <div class="newsitem">
            <div class="newsheader">
                <a href="via24960.html?id={@Id}">
                    <strong>
                        <xsl:value-of select="DocumentEdition/Fields/Field[@Name='Heading']"/>
                    </strong>
                </a>
            </div>
            <div class="newslist">
                <xsl:if test="DocumentEdition/Fields/Field[@Name='Image02'] !=''">
                    <div class="newslist_pict{DocumentEdition/Fields/Field[@Name = 'Image02Placement']}">
                        <xsl:value-of select="DocumentEdition/Fields/Field[@Name='Image02']" disable-output-escaping="yes"/>
                    </div>
                </xsl:if>
                <xsl:apply-templates select="DocumentEdition/Fields/Field[@Name='Text']"/>
            </div>
            <div class="reset">&#160;</div>
        </div>
        <hr style="height: 1px; overflow: hidden;"/>
    </xsl:template>
   
    <xsl:template match="/Module">
        <xsl:apply-templates select="//Row"/>
    </xsl:template>
   
    <xsl:template match="Row">
        <xsl:apply-templates select="Cell"/>
    </xsl:template>
   
    <xsl:template match="Cell">
        <xsl:value-of disable-output-escaping="yes" select="ContentArea"/>
    </xsl:template>
   
    <xsl:template match="Field[@Name='Text']">
        <xsl:value-of select="substring(.,1,200)"/>
        <xsl:if test="string-length(.) &gt; 200">...</xsl:if>
        <!--xsl:copy-of select="* | text()"/-->
    </xsl:template>
   
    <xsl:template match="RequestContent"/>
   
</xsl:stylesheet>
Avatar billede jokkejensen Novice
18. juni 2008 - 10:12 #5
Udfra count og maxcount kan du beregne hvor mange sider der skal findes, og udfra dem lave en form for løkke der udskriver 1, 2, 3, 4, <a href="?page=5">5</a>, 6, 7, 8 osv.
Avatar billede den-evil Nybegynder
18. juni 2008 - 10:34 #6
<xsl:for-each select="position() &gt;= 1 and position() &lt;= ceiling($doctotal div $perpage)">
                <a href="?page={position()}"><xsl:value-of select="position()" /></a>
            </xsl:for-each>
---------------------------
Men dette kan jeg ikke få lov til åbenbart, skal åbenbart vælge på et element???
Avatar billede den-evil Nybegynder
18. juni 2008 - 12:14 #7
Ligemeget, jeg fandt en løsning - siger tak for din tid i hvert fald, smider du et svar?
Avatar billede jokkejensen Novice
22. juni 2008 - 18:36 #8
super, håber jeg har været til hjælp..

Er du fra dynamic ?
Avatar billede jokkejensen Novice
22. juni 2008 - 18:37 #9
how, svar
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester