Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2008, 12:06 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formating <li> as per xml using xslt 1.0

Hi,

I need to properly nest <li> .
[list]
                <li id="L_115775_tr">
                    <xref href="http://support.microsoft.com/ph/11732" id="L_115775">Windows Vista Solution Center</xref>
                    <li id="L_116381_tr">
                        <xref href="http://support.microsoft.com/ph/8722" id="L_116381">Windows Internet Explorer 7 Solution Center</xref>
                        <li id="L_125705_tr">
                            <xref href="http://support.microsoft.com/ph/1173" id="L_125705">Windows XP Solution Center</xref>
                            <li id="L_147192_tr">
                                <xref href="http://support.microsoft.com/gp/cp_email" id="L_147192">E-mail Solution Center </xref>
                                <li id="L_140164_tr">
                                    <xref href="http://support.microsoft.com/ph/8753" id="L_140164">2007 Microsoft Office Suites Solution Center</xref>
                                </li>
                            </li>
                        </li>
                    </li>
                </li>
            </ul>




To

<p>Most popular solution centers</p>
            [list]
                <li id="L_115775_tr">
                    <xref href="http://support.microsoft.com/ph/11732" id="L_115775">Windows Vista Solution Center</xref></li>
                    <li id="L_116381_tr">
                        <xref href="http://support.microsoft.com/ph/8722" id="L_116381">Windows Internet Explorer 7 Solution Center</xref></li>
                        <li id="L_125705_tr">
                            <xref href="http://support.microsoft.com/ph/1173" id="L_125705">Windows XP Solution Center</xref></li>
                            <li id="L_147192_tr">
                                <xref href="http://support.microsoft.com/gp/cp_email" id="L_147192">E-mail Solution Center </xref></li>
                                <li id="L_140164_tr">
                                    <xref href="http://support.microsoft.com/ph/8753" id="L_140164">2007 Microsoft Office Suites Solution Center</xref></li>

            </ul>

I have been trying this but not able to resolve.

 
Old May 9th, 2008, 03:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It helps to show your attempt at the solution, then we can tell you where you went wrong. As it is, we can't tell whether you are a novice with no idea where to start, or an expert who overlooked a small point of detail.

It looks to me as if this can be done by

<xsl:template match="li">
  <li><xsl:copy-of select="@*|xref"/></li>
  <xsl:apply-templates select="li"/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 9th, 2008, 03:34 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This gives the below output[list]
        <li id="L_115775_tr" />
        <li id="L_116381_tr" />
        <li id="L_125705_tr" />
        <li id="L_147192_tr" />
        <li id="L_140164_tr" />
      </ul>
the tags inside li is lost.


 
Old May 9th, 2008, 03:38 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<li> should take all tags till starting of next <li> tag.

 
Old May 9th, 2008, 03:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It works for me. You'll have to provide your exact source document and stylesheet and explain how you ran the transformation (including details of your processor).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 9th, 2008, 04:05 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually while transformation its passing through series of xslt whic is converting the source to below
 <li id="L_116381_tr">
              <span>
                <a href="http://support.microsoft.com/ph/8722" id="L_116381">Windows Internet Explorer 7 Solution Center</a>
              </span>
              <li id="L_125705_tr">
                <span>
                  <a href="http://support.microsoft.com/ph/1173" id="L_125705">Windows XP Solution Center</a>
                </span>

So xslt should take all the nodes till starting of next <li>
but if nested ul is present [list]<li all tags[list] <li>


<li>
</li>
</li>
</ul>
<li> all tag </li>
</li>
</ul>
then it should become[list]
<li> all tags [list]
<li> all tags </li>
<li> all tags </li>
</ul>
</li>
<li> all tag </li>
</ul>

 
Old May 9th, 2008, 05:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Then in my code just replace "xref" by "*" or perhaps by "node()" depending on whether you want to include child text nodes.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 9th, 2008, 06:04 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I Used
<xsl:template match="li">
  <li><xsl:copy-of select="@*|node()"/></li>
  <xsl:apply-templates select="li"/>
</xsl:template>

The output contains all the <li> as shown below
 [list]
        <li id="L_115775_tr">
          <a href="http://support.microsoft.com/ph/11732" id="L_115775">Windows Vista Solution Center</a>
          <li id="L_116381_tr">
            <a href="http://support.microsoft.com/ph/8722" id="L_116381">Windows Internet Explorer 7 Solution Center</a>
            <li id="L_125705_tr">
              <a href="http://support.microsoft.com/ph/1173" id="L_125705">Windows XP Solution Center</a>
              <li id="L_147192_tr">
                <a href="http://support.microsoft.com/gp/cp_email" id="L_147192">E-mail Solution Center </a>
                <li id="L_140164_tr">
                  <a href="http://support.microsoft.com/ph/8753" id="L_140164">2007 Microsoft Office Suites Solution Center</a>
                </li>
              </li>
            </li>
          </li>
        </li>
        <li id="L_116381_tr">
          <a href="http://support.microsoft.com/ph/8722" id="L_116381">Windows Internet Explorer 7 Solution Center</a>
          <li id="L_125705_tr">
            <a href="http://support.microsoft.com/ph/1173" id="L_125705">Windows XP Solution Center</a>
            <li id="L_147192_tr">
              <a href="http://support.microsoft.com/gp/cp_email" id="L_147192">E-mail Solution Center </a>
              <li id="L_140164_tr">
                <a href="http://support.microsoft.com/ph/8753" id="L_140164">2007 Microsoft Office Suites Solution Center</a>
              </li>
            </li>
          </li>
        </li>
        <li id="L_125705_tr">
          <a href="http://support.microsoft.com/ph/1173" id="L_125705">Windows XP Solution Center</a>
          <li id="L_147192_tr">
            <a href="http://support.microsoft.com/gp/cp_email" id="L_147192">E-mail Solution Center </a>
            <li id="L_140164_tr">
              <a href="http://support.microsoft.com/ph/8753" id="L_140164">2007 Microsoft Office Suites Solution Center</a>
            </li>
          </li>
        </li>
        <li id="L_147192_tr">
          <a href="http://support.microsoft.com/gp/cp_email" id="L_147192">E-mail Solution Center </a>
          <li id="L_140164_tr">
            <a href="http://support.microsoft.com/ph/8753" id="L_140164">2007 Microsoft Office Suites Solution Center</a>
          </li>
        </li>
        <li id="L_140164_tr">
          <a href="http://support.microsoft.com/ph/8753" id="L_140164">2007 Microsoft Office Suites Solution Center</a>
        </li>
      </ul>

 
Old May 9th, 2008, 06:41 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It doesn't feel to me as if you are trying to help yourself. I gave the solution to your original problem as stated, and you should really be able to work out how to adapt it to your revised problem without hand-holding - it you can't, then you really need to do some reading around the language.

Try apply-templates select="@* | node()[not(self::li)]"

and if that doesn't work, then please try and work out why before posting again.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 12th, 2008, 01:30 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried this also but its also not working Its copying only first node . To solve this I broked the problem into two parts
1. Copy the all nodes below <li>
This is working using
<xsl:template match="li">
  <li><xsl:copy-of select="@*"/>

      <xsl:apply-templates select="node()"/>


</li>
</xsl:template>
I tried using
<xsl:apply-templates select="preceding-sibling::*" />
thats not working.
Next problem is to copy till occurence of next <li>.
Here I am stuck. This is the one of issue where I am stuck.






Similar Threads
Thread Thread Starter Forum Replies Last Post
<li></li> issue Adam H-W CSS Cascading Style Sheets 1 November 5th, 2007 06:41 AM
How do I transform XSLT without the <?xml?> tag? nadavvin XSLT 4 June 10th, 2007 09:25 AM
How To PopUp Text Message within <li> tclotworthy Javascript How-To 1 February 18th, 2007 09:07 PM
create <ul> with alternating class on <li> element Brian Campbell XSLT 2 November 3rd, 2006 06:07 PM
color attribute with <li> econophil HTML Code Clinic 2 August 31st, 2004 02:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.