You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Kalcevich, Daniel" <dk...@firstam.com> on 2005/11/09 19:12:36 UTC
XSL for-each problem
Everyone,
I am trying to transform a stylesheet and I am running into a problem
with the <xsl:for-each> element. I want to select all <violation>
elements underneath the <violations> element. There are 3 shown in the
XML below. Anyways, I am trying to use the XPath query
"//listing/violations/violation" but when I do, it loops through my code
12 times! I am trying to find the right XPath query so that it only
searches 3 times. Any help is appreciated. Any help is appreciated!
Thanks.
//////////////////////////// XML File //////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<listing>
<violations>
<violation>
<violation_num>2.4</violation_num>
<violation_type_desc>Misuse of Public
Remarks</violation_type_desc>
<violation_mlsrule_no>MLs rule for id
2</violation_mlsrule_no>
<violation_desc>some description for Violation ID :
2</violation_desc>
<examples>
<violation_example>Example 1</violation_example>
<violation_example>Example 2</violation_example>
</examples>
</violation>
<violation>
<violation_num>1.3</violation_num>
<violation_type_desc>Misuse of Agent
Remarks</violation_type_desc>
<violation_mlsrule_no>MLS rule ID
3</violation_mlsrule_no>
<violation_desc>something with violation id 3
</violation_desc>
<examples>
<violation_example>Example 3</violation_example>
<violation_example>Example4</violation_example>
</examples>
</violation>
<violation>
<violation_num>1.3</violation_num>
<violation_type_desc>Misuse of Agent
Remarks</violation_type_desc>
<violation_mlsrule_no>MLS rule ID
3</violation_mlsrule_no>
<violation_desc>something with violation id 3
</violation_desc>
<examples>
<violation_example>Example 5</violation_example>
</examples>
</violation>
</violations>
</listing>
</xml>
//////////////////// XSL
<xsl:for-each select="//listing/violations/violation">
<xsl:value-of selec="violation_num"/>
</xsl:for-each>
Daniel Kalcevich
Software Engineer
SCJP,SCWCD
ext. 7503
Re: XSL for-each problem
Posted by Christine Li <jy...@ca.ibm.com>.
Hi, Daniel
I can't tell why you got wrong result without seeing your stylesheet. Post
your stylesheet, I may help.
Christine Li
XSLT Development
IBM Toronto Lab
Tel: (905)413-2601
Email: jycli@ca.ibm.com
"Kalcevich, Daniel" <dk...@firstam.com>
09/11/2005 01:12 PM
To
xalan-j-users@xml.apache.org
cc
Subject
XSL for-each problem
Everyone,
I am trying to transform a stylesheet and I am running into a problem with
the <xsl:for-each> element. I want to select all <violation> elements
underneath the <violations> element. There are 3 shown in the XML below.
Anyways, I am trying to use the XPath query
?//listing/violations/violation? but when I do, it loops through my code
12 times! I am trying to find the right XPath query so that it only
searches 3 times. Any help is appreciated. Any help is appreciated!
Thanks.
//////////////////////////// XML File //////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<listing>
<violations>
<violation>
<violation_num>2.4</violation_num>
<violation_type_desc>Misuse of Public
Remarks</violation_type_desc>
<violation_mlsrule_no>MLs rule for id
2</violation_mlsrule_no>
<violation_desc>some description for Violation ID :
2</violation_desc>
<examples>
<violation_example>Example 1</violation_example>
<violation_example>Example 2</violation_example>
</examples>
</violation>
<violation>
<violation_num>1.3</violation_num>
<violation_type_desc>Misuse of Agent
Remarks</violation_type_desc>
<violation_mlsrule_no>MLS rule ID 3</violation_mlsrule_no>
<violation_desc>something with violation id 3
</violation_desc>
<examples>
<violation_example>Example 3</violation_example>
<violation_example>Example4</violation_example>
</examples>
</violation>
<violation>
<violation_num>1.3</violation_num>
<violation_type_desc>Misuse of Agent
Remarks</violation_type_desc>
<violation_mlsrule_no>MLS rule ID 3</violation_mlsrule_no>
<violation_desc>something with violation id 3
</violation_desc>
<examples>
<violation_example>Example 5</violation_example>
</examples>
</violation>
</violations>
</listing>
</xml>
//////////////////// XSL
<xsl:for-each select=?//listing/violations/violation?>
<xsl:value-of selec=?violation_num?/>
</xsl:for-each>
Daniel Kalcevich
Software Engineer
SCJP,SCWCD
ext. 7503