Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • syn-rg 282 posts 425 karma points
    May 17, 2012 @ 08:50
    syn-rg
    0

    Retrieve first paragraph and first image from child node?

    Is it possible to retrieve the first paragraph and first image from a child node?
    The image will be in the rich text editor, from the Media section.

    Any ideas?

    Cheers, JV

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 17, 2012 @ 11:13
    Lee Kelleher
    0

    Hi JV,

    There are a few ways to achieve this, but would require custom code to do so.

    My suggestion would be to make use of a uComponents XSLT extension to parse the XHTML from the rich-text editor into XML and use XSLT to format it accordingly.

    Rough example code would be like this...

    <xsl:variable name="html" select="ucomponents.xml:Parse(bodyText)" />
    <xsl:copy-of select="$html/p[1]"/>
    <xsl:if test="$html//img">
        <xsl:copy-of select="$html//img[1]"/>
    </xsl:if>

    Cheers, Lee.

  • syn-rg 282 posts 425 karma points
    May 21, 2012 @ 08:18
    syn-rg
    0

    Hi Lee,

    I've added uComponents and have added the code to my XSLT without any joy. It doesn't show any of the bodyText from the child node.

    Here's my XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:RVContactForm.XsltExtensions="urn:RVContactForm.XsltExtensions" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" xmlns:UCommentLibrary="urn:UCommentLibrary" xmlns:ucomponents.xml="urn:ucomponents.xml"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets RVContactForm.XsltExtensions ucomponents.xml ucomponents.strings PS.XSLTsearch UCommentLibrary ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:variable name="html" select="ucomponents.xml:Parse(bodyText)" />

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
      
      <xsl:copy-of select="$html/p[1]"/>
      <xsl:if test="$html//img">
        <xsl:copy-of select="$html//img[1]"/>
      </xsl:if>
      
    </xsl:template>

    </xsl:stylesheet>
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 21, 2012 @ 10:48
    Lee Kelleher
    0

    Hi JV,

    You'll need to bring the "html" variable inside the <xsl:template> and modify it to...

    <xsl:variable name="html" select="ucomponents.xml:Parse($currentPage/bodyText)" />

    That is, if your property alias for the rich-text editor is called "bodyText", otherwise change it to whatever you are using.

    Cheers, Lee.

  • syn-rg 282 posts 425 karma points
    May 22, 2012 @ 02:29
    syn-rg
    0

    Hi Lee,

    I've added the variable inside the template, however it only pulls in the current page HTML not the child nodes.


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
        
    <xsl:template match="/">
      
      <xsl:variable name="html" select="ucomponents.xml:Parse($currentPage/mainContent)" />
      <div class="sub_page_list">
        <ul>
          <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']">
            <xsl:copy-of select="$html/p[1]"/>
            <xsl:if test="$html/img">
              <xsl:copy-of select="$html/img[1]"/>
            </xsl:if>
          </xsl:for-each>
        </ul>
      </div>
      
    </xsl:template>

    How can I get it to display the child nodes?

    Cheers, JV

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 22, 2012 @ 11:02
    Lee Kelleher
    0

    Hi JV,

    You would need to the move the "html" variable inside the for-each loop, as at the moment it is only getting from the current page.

     <div class="sub_page_list">
        <ul>
            <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']">
                <xsl:variable name="html" select="ucomponents.xml:Parse(mainContent)" />
                <xsl:copy-of select="$html/p[1]"/>
                <xsl:if test="$html/img">
                    <xsl:copy-of select="$html/img[1]"/>
                </xsl:if>
            </xsl:for-each>
        </ul>
    </div>

    Cheers, Lee.

  • syn-rg 282 posts 425 karma points
    May 22, 2012 @ 13:21
    syn-rg
    0

    Hi Lee,

    I've tried that but it doesn't pull in the child page, it pulls in the required two LI's but none of content.

    Here's the result:

    <ul>
    <li></li>
    <li></li>
    </ul>

    Here's what I've got so far:

    <ul>
              <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']">
                <li>
                  <xsl:variable name="html" select="ucomponents.xml:Parse(mainContent)" />
                  <xsl:copy-of select="$html/p[1]"/>
                  <xsl:if test="$html/img">
                    <xsl:copy-of select="$html/img[1]"/>
                  </xsl:if>
                </li>
              </xsl:for-each>
            </ul>
  • syn-rg 282 posts 425 karma points
    May 23, 2012 @ 09:40
    syn-rg
    0

    The following XSLT results in this error on the live page:

    <ul>
    <li>
    <exception type="System.Xml.XmlException">
    <message>There are multiple root elements. Line 8, position 2.</message>
    <stacktrace>System.Xml.XmlTextReaderImpl.Throw(String res, String arg)System.Xml.XmlTextReaderImpl.ParseDocumentContent()System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)System.Xml.XPath.XPathDocument..ctor(TextReader textReader)uComponents.Core.XsltExtensions.Xml.ParseXml(String xml, String xpath)</stacktrace>
    </exception>
    </li>
    <li>
    <exception type="System.Xml.XmlException">
    <message>There are multiple root elements. Line 8, position 2.</message>
    <stacktrace>System.Xml.XmlTextReaderImpl.Throw(String res, String arg)System.Xml.XmlTextReaderImpl.ParseDocumentContent()System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)System.Xml.XPath.XPathDocument..ctor(TextReader textReader)uComponents.Core.XsltExtensions.Xml.ParseXml(String xml, String xpath)</stacktrace>
    </exception>
    </li>
    </ul>

    This is the XSLT:

            <ul>
              <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']">
                <li>
                  <xsl:variable name="html" select="ucomponents.xml:Parse(mainContent)" />
                  <xsl:copy-of select="$html" />

                  <xsl:if test="$html/img">
                    <xsl:copy-of select="$html/img[1]"/>
                  </xsl:if>
                </li>
              </xsl:for-each>
            </ul>

    Notice that I'm using select="$html" not "$html/p[1]"

  • syn-rg 282 posts 425 karma points
    Jun 14, 2012 @ 08:31
    syn-rg
    0

    I've made some changes and am now using the uComponents "Get First Words" string.

    Still wondering whether it's possible to restrict it just to the first paragraph.

    Haven't figured out how to display any of the child page images. The images are added into the RTE.

    Thus far here is the result:

    <div class="sub_page_list">
    <ul>
    <li>
    <h3>Electricity Industry Framework</h3>
    <p>Ut aliquat lobore commy nullan velent lam velis doloreet, quat, vel ulluptatie faci tet, sequate consequatue conseniamet nisim vullamcor se commy nis nibh eu feu feummy nonsenit, suscilit del dignibh exero erit iriliquipisi eu faciliqui blan ver sit, quis at. Idui blaorem aliquat aut in henisi. Lorem Ipsum Delor Oborper ipis aciliquis dolortio dit adit aliquam, vent iure magnis am zzrit, vullaore del dunt laore verostrud ea facil ut ver sumsan utat. Ut praesequis aci ero endre feuismo lessis et, quam zzriliquamet la faccum quisl utem augait ad modo consed digna faci et utpatin et voluptat. Hent aut iurem alit <a href="/about-us/regulatory-framework/electricity-industry-framework.aspx" class="arrow">More information</a></p>
    </li>
    <li>
    <h3>Gas Industry Framework</h3>
    <p>Ut aliquat lobore commy nullan velent lam velis doloreet, quat, vel ulluptatie faci tet, sequate consequatue conseniamet nisim vullamcor se commy nis nibh eu feu feummy nonsenit, suscilit del dignibh exero erit iriliquipisi eu faciliqui blan ver sit, quis at. Idui blaorem aliquat aut in henisi. Lorem Ipsum Delor Oborper ipis aciliquis dolortio dit adit aliquam, vent iure magnis am zzrit, vullaore del dunt laore verostrud ea facil ut ver sumsan utat. Ut praesequis aci ero endre feuismo lessis et, quam zzriliquamet la faccum quisl utem augait ad modo consed digna faci et utpatin et voluptat. Con vulputpat nibh exero <a href="/about-us/regulatory-framework/gas-industry-framework.aspx" class="arrow">More information</a></p>
    </li>
    </ul>
    </div>

    Here is the XSLT:

      <xsl:choose>
        <xsl:when test="$currentPage/listSubPages = 1">
          <div class="sub_page_list">
            <ul>
              <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']">
                <li>
                  <xsl:choose>
                    <xsl:when test="pageNames != ''">
                      <h3><xsl:value-of select="pageNames"/></h3>
                    </xsl:when>
                    <xsl:otherwise>
                      <h3><xsl:value-of select="@nodeName"/></h3>
                    </xsl:otherwise>
                  </xsl:choose>
                  <p><xsl:value-of select="ucomponents.strings:GetFirstWords(umbraco.library:StripHtml(./mainContent), 100,' ')" /> <a href="{umbraco.library:NiceUrl(@id)}">More information</a></p>
                </li>
              </xsl:for-each>
            </ul>
          </div>
        </xsl:when>
      </xsl:choose>

    Cheers, JV

  • syn-rg 282 posts 425 karma points
    Jun 18, 2012 @ 02:11
    syn-rg
    0

    Got it working, here's the final XSLT:

    <xsl:template match="/">
      
      <xsl:choose>
        <xsl:when test="$currentPage/listSubPages = 1">
          <div class="sub_page_list">
            <ul>
              <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']">
                <li>
                  <xsl:choose>
                    <xsl:when test="pageNames != ''">
                      <h3><xsl:value-of select="pageNames"/></h3>
                    </xsl:when>
                    <xsl:otherwise>
                      <h3><xsl:value-of select="@nodeName"/></h3>
                    </xsl:otherwise>
                  </xsl:choose>
                  <!--<p><xsl:value-of select="ucomponents.strings:GetFirstWords(umbraco.library:StripHtml(./mainContent), 100,' ')" /> <a href="{umbraco.library:NiceUrl(@id)}">More information</a></p>-->
                  <xsl:variable name="rawHtml">
                    &lt;mydata&gt;
                    <xsl:value-of select="./mainContent" />
                    &lt;/mydata&gt;
                  </xsl:variable>
                  <xsl:variable name="html" select="ucomponents.xml:Parse($rawHtml)/mydata" />
                  <xsl:variable name="firstImage" select="$html/descendant::*[name()='img']" />
                  <xsl:if test="count($firstImage) > 0">
                    <xsl:copy-of select="$firstImage"/>
                  </xsl:if>
                  <xsl:copy-of select="$html/p[1]"/>
                  <a href="{umbraco.library:NiceUrl(@id)}">More information</a>
                </li>
              </xsl:for-each>
            </ul>
          </div>
        </xsl:when>
      </xsl:choose>
      
    </xsl:template>
Please Sign in or register to post replies

Write your reply to:

Draft