 |
| 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
|
|
|
|

December 11th, 2009, 08:46 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
loop over similiar tags
Hello all,
Using XSLT 1.0
I have the following xml structure below. There must always be the first <DEWS tag, but the rest are optional. If there was a second dews tag it would be dews2 and so on. Now how do i loop over these tags in a for-each statement? Is this possible?
Code:
<record>
<DEWS1>DC22</DEWS1>
<DEWS2>DC23</DEWS1>
<DEWS3>DC24</DEWS1>
<DEWS4>DC25</DEWS1>
<DEWS5>DC26</DEWS1>
</record
Help would be much appreciated
Regards.
|
|

December 11th, 2009, 08:51 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Doesn't
Code:
<xsl:for-each select="/record/*">...</xsl:for-each>
suffice?
Or you could use
Code:
<xsl:for-each select="/record/*[starts-with(local-name(), 'DEWS')]">...</xsl:for-each>
if there are other child elements of 'record' you don't want to process.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

December 11th, 2009, 09:21 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
Thanks Martin,
yeah there are other children so the second one is needed. I forgot about local-name.
Regards.
|
|

December 11th, 2009, 09:54 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
Hi, I am trying to get the first preceding value of CR for the type value
But it just seems to return the same value for both author records. Any ideas?
Code:
<xsl:for-each select="*[starts-with(local-name(), 'ICFN')]">
<author>
<name><xsl:value-of select="concat(.,', ',following-sibling::*[1])"/></name>
<type><xsl:value-of select="preceding-sibling::*[starts-with(local-name(),'CR')]"/></type>
</author>
</xsl:for-each>
<record>
<CR1>asdfasdf</CR1>
<CRT1>Edited by</CRT1>
<CCI1>N</CCI1>
<ICFN1>Adnan</ICFN1>
<ICKN1>Ibrahimbegovic</ICKN1>
<CR2>B01</CR2>
<CRT2>Edited by</CRT2>
<CCI2>N</CCI2>
<ICFN2>Muhamed</ICFN2>
<ICKN2>Zlatar</ICKN2>
</record>
Regards,
John.
|
|

December 11th, 2009, 09:58 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
preceding-sibling::*[starts-with(local-name(),'CR')][1]
And it probably doesn't help that the value is the SAME for both records.
|
|

December 11th, 2009, 09:58 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
That snippet you posted has a 'CRT1' element and a 'CRT2' element, but both have the same contents 'Edited by' so I am not sure why you complain about getting the same value.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

December 11th, 2009, 10:13 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
That was just a copy and paste error in the xml, normally they have different values. Thanks a lot
|
|

December 11th, 2009, 10:38 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
This is a horrible XML design. Do you have any control over it? There seems to be a sequence of XXX1 elements representing the first record, then a sequence of XXX2 elements representing the second record, and so on: so put each of these sequences inside a wrapper element, and use the same tags in each one.
If you can't get the design of the XML changed at source, it's worth transforming it into something more sanitory before you attempt any other kind of transformation. Then you only have to write the "sanitization" code once - everthing else will be able to start with clean input.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

December 11th, 2009, 10:52 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
No i have no control over it. It is the Nielsen BookData Web Service: XML Format Field Specification
Regards.
|
|
 |