XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> - XSL-fo and how to line feed th... (1)
-> + Houston we have a problem (2)
-> + XSL-FO PDF generation (2)
-> + StylusStudio - pick XSLT 1.0 b... (6)
-> - Stylus Studio 2010 debugging f... (1)
-> - Drop down menu List / Option M... (1)
-> - XML transformation using Java ... (1)
-> + i can't to find XSLT editor in... (2)
-> - Copy xml input as value of an ... (1)
-> - Remove Name space from the Tab... (1)
-> - CGI formatted URL with name/va... (1)
-> - Problem with counting (1)
-> + for-each loop is only returnin... (3)
-> - sort date but some dates may b... (1)
-> - Entity Conversion (1)
-> - How can I build an xml convert... (1)
-> + Little Help (2)
-> + how do I merge nodes to one sc... (2)
-> - beginner help xslt and xpath (1)
-> - Convert XML Feed to CSV/SQL/XL... (1)
-> - Working with text node. (1)
-> - No Topic (1)
-> - API for XSLT Converter for .NE... (1)
-> - Getting started (1)
-> + saxon sql extensions - mysql a... (2)
-> - How do I copy and create new e... (1)
-> + substring-before and sums (3)
-> + Parsing special characters in ... (2)
-> + Schema - Require attribute in ... (2)
-> - Edit existing XSL files when n... (1)
-> + How can I use one single XSLT ... (2)
-> - Default selection of value in ... (1)
-> - Problem with watermark in pdf ... (1)
-> + XSLT Parameter Values dialog n... (3)
-> + Value of File Name is not acce... (10)
-> - Need help with a complex table... (1)
-> - How to replace all nordic char... (1)
-> - XSLT java heap space error wit... (1)
-> - Table Overflow to next page (1)
-> - Using XSLT 2.0 to define custo... (1)
-> - "standalone" attribute and xs... (1)
-> + Standardizing IP addresses (2)
-> + Programmatically changing page... (6)
-> + Can Stylus generate XSLT if so... (5)
-> + Extraction based on NODE Name. (2)
-> + NO XSLT:WYSIWYG (2)
-> + determine condition at run tim... (2)
-> - How to reduce top margin in ev... (1)
-> + need help on xsl looping (4)
-> - Convert Symbol to Element (1)
-> + Separator -only- between field... (3)
-> + DocBook (9)
-> + First Occurance of Alphabet (2)
-> + XSL:Key and Document (2)
-> + Excel Macro using XSLT (2)
-> + Add missing element and attrib... (2)
-> + XSL: Stop Count at First Match (2)
-> + XSD to EDI (4)
-> + How to access data from nested... (2)
-> + Simple division of XML file (2)
-> - XML to Flat File (1)
-> + Dispalying data whith xsl:for ... (3)
-> - distinct nodes - into 3 column... (1)
-> + Newbie at XML (2)
-> + XSL Not Working (3)
-> + to draw table using xsl (2)
-> + Base64 decoder (5)
-> + How to create a hidden sheet u... (3)
-> + XML Reports (2)
-> + Copying image files from one d... (2)
-> + XML conversion to RSS (2)
-> + Inserting Image (2)
-> + Xml to Pdf using Xsl (2)
-> + Using a parameter (or similar)... (2)
-> + How to avoid creating empty xm... (2)
-> + how to read txt files in xml (2)
-> + Limit records to 4 per page. P... (4)
-> + XSLT Mapping Based on JDK5 (2)
-> + XML Mappin (2)
-> + Format Datetime with xslt (3)
-> + Cell border missing (2)
-> + XSL: Key (not matches) (5)
-> + Loop through each char in stri... (2)
-> + What is the best way to sum va... (3)
-> + xslt sort help (2)
-> + getting the count (2)
-> + XSL dynamic variables (5)
-> + XSL:Key use (3)
-> + Help With Updating Attributes ... (8)
-> + GETTING COUNT AND POSITION usi... (3)
-> - Hi Everyone !! (1)
-> + Graph Traversal (Keep track of... (2)
-> + XSL IF with sum (2)
-> + Param not incrementing (2)
-> + Iterating through value tags (3)
-> + URGENT :::: Remove the name sp... (2)
-> + Pass new param values to ASP O... (2)
-> + Detect Browser Version in XSL (2)
-> + xslt result-document (2)
-> + Unique nodes based on two attr... (3)
-- Previous [181-200] [201-220] [221-240] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 25 Oct 2005 11:05 AM
Im trying to display n number of article sections
from an xml file using xsl.

I want to select all the section nodes
then loop through the types one node at a time
so when the node type matchs the correct
formatting is used.
however im not having any luck i keep getting
errors on one of the line.

<xsl:if test="boolean(product_sheet/section)">
lookie
<xsl:for-each select="child::product_sheet/section">
beep
<xsl:if test = "product_sheet/child::section==listgroup">
beep2
<xsl:for-each select="//listgroup/list">
<li><xsl:value-of select="current()"/></li>
<br>here</br>
</xsl:for-each>
<br></br>
</xsl:if>
</xsl:for-each>
</xsl:if>

Beep 2 is not showing.
the xpath listing for list is
product_sheet/section/listgroup/list.

What am I doing wrong? or am i totally going the wrong way about this?

Postnext
(Deleted User) Subject: Xpath problem
Author: (Deleted User)
Date: 25 Oct 2005 11:09 AM
Can you publish your XML file ?

Postnext
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 25 Oct 2005 11:15 AM

Its still a bit rough, here all 3 reference files.
xml file

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="style_template.xsl"?>
<!-- programmer: mary gilmartin. date: oct 05 -->
<product_sheet xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="example.xsd">
<id>203</id>
<title>45030405.doc</title>
<type>cleaning chemicals</type>
<subtype>floor</subtype>
<banner>altova.gif</banner>
<main_heading>PRODUCT DATA SHEET</main_heading>
<product_name>DYCLEAN</product_name>
<subheading>Product Description</subheading>

<section>
<link>http://www.google.ie</link>
<listgroup>
<list>An advanced cationic cleaning solution for cleaning areas where bacterial control is not an issue.</list>
<list>Odourless, heavy-duty cleaner and degreaser.</list>
<list>Use for periodic of all Dycem products.</list>
<list>Concentrated mix for dilution with water.</list>
</listgroup>
</section>
<subheading>Product Properties</subheading>
<section>
<tableb>
<row>
<col>Parameter</col>
<col>Specification</col>
</row>
<row>
<col>General appearance</col>
<col>Cobalt Blue Mobile Liquid</col>
</row>
<row>
<col>Odour</col>
<col>Negligible</col>
</row>
<row>
<col>PH @20C</col>
<col>12.50-13.50</col>
</row>
<row>
<col>Solubility in Water</col>
<col>Soluble- mix as per recommended dilution</col>
</row>
</tableb>
<image>blah.gif</image>
<listgroup>
<list>Five Litre container</list>
<list>2 x 5 litre container per case</list>
</listgroup>
<note></note>
</section>

<tlink>http://www.yahoo.com</tlink>
<mail>quote@atp.com</mail>
</product_sheet>
<?xml-stylesheet type="text/xsl" href="style_template.xsl"?>

--------------------------------------
Schema

<?xml version="1.0" encoding="UTF-8" ?>
- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
- <!-- programmer: mary gilmartin. date: oct 05
-->
- <!-- definition of page complex element
-->
- <xs:element name="product_sheet">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <!-- document header elements
-->
<xs:element name="type" type="xs:string" />
<xs:element name="subtype" type="xs:string" />
<xs:element name="id" type="xs:string" />
<xs:element name="title" type="xs:string" />
<xs:element name="banner" />
<xs:element name="main_heading" type="xs:string" />
<xs:element name="product_name" type="xs:string" />
<xs:element name="subheading" type="xs:string" />
- <!--
section element, tables, paragraphs, images
lists, links, mailto

-->
- <xs:element name="section">
- <xs:complexType mixed="true">
- <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="paragraph" type="xs:string" />
- <xs:element name="listgroup">
- <xs:complexType mixed="true">
- <xs:sequence>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="list" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
- <!-- tables i intend to border
-->
- <xs:element name="tableb">
- <xs:complexType>
- <xs:sequence>
- <xs:choice maxOccurs="unbounded">
- <xs:element name="row">
- <xs:complexType>
- <xs:sequence>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="col" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
- <!-- tables i intend to leave without borders
-->
- <xs:element name="tablenb">
- <xs:complexType>
- <xs:sequence>
- <xs:choice maxOccurs="unbounded">
- <xs:element name="row">
- <xs:complexType>
- <xs:sequence>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="col" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="image" type="xs:string" />
<xs:element name="note" type="xs:string" />
<xs:element name="link" type="xs:string" />
</xs:choice>
</xs:complexType>
</xs:element>
- <!-- document footer elements
-->
<xs:element name="mail" type="xs:string" />
<xs:element name="tlink" type="xs:string" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
------------------------------------------------------
xsl file

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- programmer: mary gilmartin. date: oct 05. company:ATP -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="product_sheet/main_heading"/></title>
</head>
<body bgcolor='white'>

<!-- Generalised code for outputting images (img not showing) -->
<img scr="{product_sheet/banner}"/>

<h2><xsl:value-of select="product_sheet/main_heading"/></h2>
<h3><xsl:value-of select="product_sheet/product_name"/></h3>
<br><b><li><xsl:value-of select="product_sheet/subheading"/></li></b></br>

<!-- Attempt at generalised sections
if there is section tags show the section elements
need to iterate through the nodes to place
them in the order the xml file declares them in -->
<xsl:if test="boolean(product_sheet/section)">
lookie
<xsl:for-each select="child::product_sheet/section">
beep
<xsl:if test = "product_sheet/child::section==listgroup">
the first child in the section nodetree is a list
<xsl:for-each select="//listgroup/list">
<li><xsl:value-of select="current()"/></li>
<br>here</br>
</xsl:for-each>
<br></br>
</xsl:if>
</xsl:for-each>
</xsl:if>


<!-- old code -->
<br></br>
<!-- Need to generalised paragraph location -->
<xsl:for-each select="product_sheet/section/listgroup/list">
<li><xsl:value-of select="current()"/></li>
<br></br>
</xsl:for-each>
<br></br>

<!-- generic links -->
<a>
<xsl:attribute name = "href">
<xsl:value-of select = "product_sheet/section/link"/>
</xsl:attribute>
<xsl:value-of select = "product_sheet/section/link"/>
</a>

<br><b><li><xsl:value-of select="product_sheet/subheading[2]"/></li></b></br>

<!-- Generalised code for outputting any table with a border-->
<table border='1' cellpadding='2'>
<xsl:for-each select="product_sheet/section/tableb/row">
<tr>
<xsl:for-each select="col">
<td>
<xsl:value-of select="current()"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
<br></br>

<!-- Generalised code for outputting any borderless table -->
<table border='0' cellpadding='2'>
<xsl:for-each select="product_sheet/section/tablenb/row">
<tr>
<xsl:for-each select="col">
<td>
<xsl:value-of select="current()"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
<br></br>

<!-- Need to generalised paragraph location -->
<xsl:for-each select="product_sheet/section[2]/listgroup/list">
<li><xsl:value-of select="current()"/></li>
<br></br>
</xsl:for-each>
<br></br>

<!-- generic links outside section blocks-->
<a>
<xsl:attribute name = "href">
<xsl:value-of select = "product_sheet/tlink"/>
</xsl:attribute>
<xsl:value-of select = "product_sheet/tlink"/>
</a>
<br></br>

<!-- generic mailto -->
<a>
<xsl:attribute name = "href">mailto:
<xsl:value-of select = "product_sheet/mail"/>
</xsl:attribute>
<xsl:value-of select = "product_sheet/mail"/>
</a>
<br></br>

</body>
</html>
</xsl:template>
</xsl:stylesheet>
-------------------------------

Postnext
(Deleted User) Subject: Xpath problem
Author: (Deleted User)
Date: 25 Oct 2005 11:34 AM
You probably want to replace "==" with "=" in
<xsl:if test="product_sheet/child::section==listgroup">

Postnext
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 25 Oct 2005 11:36 AM
That just creates

XSLT 1.0 Debugging Error: Invalid XPath expression
in XMLSpy.

Postnext
(Deleted User) Subject: Xpath problem
Author: (Deleted User)
Date: 25 Oct 2005 12:03 PM
You actually want to have this line :

<xsl:if test="local-name(child::*[1])='listgroup'">

if you want to have a condition "first child element of the section is listgroup"

because within this loop :

<xsl:for-each select="child::product_sheet/section">

your current node will be 'section'

We've executed your XSLT using msxml, Saxon and Xalan J, and .NET processors. All of them generated HTML page.

We are Stylus Studio team, not Altova XML Spy team, and we do not provide any support for Altova XML Spy.

Postnext
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 25 Oct 2005 12:22 PM
Originally Posted: 25 Oct 2005 12:09 PM
Oh Im not looking for support (Im sure my problem is code) just xsl/xpath advise. The page generates due to old code. but the new code wasnt showing as beep2 wasnt coming up. I'll try out the new line. . . . Beep2 still isnt showing.

Postnext
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 25 Oct 2005 12:20 PM
Ok maybe my problem is logical.

If you have a parent node <section>
with 4 possible child nodes
<image><listgroup><paragaph><table>.

And in the xml document
a <section> can contain any of the child
nodes in any number or any order.

I want to format the nodes
but keep the order they are in,
in the xml file. (data driven xsl)

so logical i want to test first
is there anything in the section.

then looping through the different
<section nodes> with a for-each

I test each child node as i find it
to see what type of node it is.

If its <listnode>
i display it by looping through
the <list> nodes and adding html tags.

Is this good practice?
If it is then my code isnt matching
what im trying to do.
If it isnt, then my method is flawed.

Postnext
(Deleted User) Subject: Xpath problem
Author: (Deleted User)
Date: 25 Oct 2005 01:55 PM
Creating XML from your test case we will have something like this :

<?xml version="1.0"?>
<section>
<image>Image1</image>
<image>Image2</image>
<listgroup>Listgroup1</listgroup>
<paragraph>Paragraph1</paragraph>
<paragraph>Paragraph2</paragraph>
<listgroup>Listgroup1</listgroup>
<paragraph>Paragraph3</paragraph>
<table>Table</table>
<p>This is some text which will stay unchanged</p>
</section>

Suggested XSLT will look like :


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>

<xsl:template match="/">
<html>
<head>
<title>Sample XSLT</title>
</head>
<body bgcolor="white">
<!-- We will iterate over direct children of section -->
<xsl:for-each select="section/*">
<!-- Current node "." here is section child -->
<xsl:apply-templates select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>

<!-- If this is "image" we will create HTML list item with
image text using red color -->
<xsl:template match="image">
<font color="red">
<li>
<xsl:value-of select="text()"/>
</li>
</font>
</xsl:template>

<!-- If this is "listgroup" we will create HTML list item with
image text using green color -->
<xsl:template match="listgroup">
<font color="green">
<li>
<xsl:value-of select="text()"/>
</li>
</font>
</xsl:template>


<!-- If this is "paragraph" we will create HTML list item with
image text using blue color -->
<xsl:template match="paragraph">
<font color="blue">
<li>
<xsl:value-of select="text()"/>
</li>
</font>
</xsl:template>

<!-- If this is "table" we will create HTML list item with
image text using yellow color -->
<xsl:template match="table">
<font color="yellow">
<li>
<xsl:value-of select="text()"/>
</li>
</font>
</xsl:template>

<!-- For all other elements we will do full copy -->
<xsl:template match="*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

Now let's take a look why in your case this condition

<xsl:if test="local-name(child::*[1])='listgroup'">

never evaluates into "true".

Let's take first case where it can potentially match :

<section>
<link>http://www.google.ie</link>
<listgroup>
<list>An advanced cationic cleaning solution for cleaning areas where bacterial control is not an issue.</list>
<list>Odourless, heavy-duty cleaner and degreaser.</list>
<list>Use for periodic of all Dycem products.</list>
<list>Concentrated mix for dilution with water.</list>
</listgroup>
</section>

in this case "listgroup" is the second child element of "section" and
condition evaluates into "false". If you change XML this way :

<section>
<listgroup>
<list>An advanced cationic cleaning solution for cleaning areas where bacterial control is not an issue.</list>
<list>Odourless, heavy-duty cleaner and degreaser.</list>
<list>Use for periodic of all Dycem products.</list>
<list>Concentrated mix for dilution with water.</list>
</listgroup>
<link>http://www.google.ie</link>
</section>

"listgroup" becomes first child element of "section" and you'll get your <li> output.


Postnext
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 26 Oct 2005 04:17 AM
Thanks that highlighted my problem.
Ill work with this information
and see can i fix it.
The way you used templates might really help.

Postnext
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 26 Oct 2005 04:48 AM
Is it possible to apply-templates from a template?

for example

if i did this
<xsl:for-each select="root_node/*">
<!-- go to all the children of the root node-->
<xsl:apply-templates select="."/>
</xsl:for-each>

<xsl:template match="child_of_root">
<!-- apply templates to the children of child_or_root -->
<xsl:for-each select="child_of_root/*">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>

in order for the top level nodes to be matchedv in order
and the system to match the children of the lower level nodes
as it went along.

like:

a
b
b1
b2
c

or would it be better to instead of matching the
children of the root node, matching the
descendants of the root node.

What would be the different in display order?

Posttop
Mary GilmartinSubject: Xpath problem
Author: Mary Gilmartin
Date: 26 Oct 2005 07:27 AM
Originally Posted: 26 Oct 2005 07:10 AM
Its possible. Thank you. Its working as I want it too now.

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.