| Newsgroups |
gmane.text.xml.xsl.general.mulberrytech |
| Message-ID |
<[email protected]> |
This is a multipart message in MIME format.
------=_NextPart_000_044E_01D74D93.F2E40500
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Here is my sample input:
<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
<DH675AU>
<FIG_NO>99999</FIG_NO>
<PART_DES>DIPSTICK</PART_DES>
</DH675AU>
<DH675AU>
<FIG_NO>99999</FIG_NO>
<PART_DES>O-RING</PART_DES>
</DH675AU>
<DH675AU>
<FIG_NO>99999</FIG_NO>
<PART_DES>SCREW, SELF-TAPPING</PART_DES>
</DH675AU>
<DH675AU>
<FIG_NO>99999</FIG_NO>
<PART_DES>NOTE: (1) NOT SERVICED SEPARATELY. INCLUDED IN</PART_DES>
</DH675AU>
<DH675AU>
<FIG_NO>99999</FIG_NO>
<PART_DES>58F-98-40740 SEAL KIT.</PART_DES>
</DH675AU>
<DH675AU>
<FIG_NO>69500</FIG_NO>
<PART_DES>DIPSTICK</PART_DES>
</DH675AU>
<DH675AU>
<FIG_NO>69500</FIG_NO>
<PART_DES>O-RING</PART_DES>
</DH675AU>
<DH675AU>
<FIG_NO>69500</FIG_NO>
<PART_DES>SCREW, SELF-TAPPING</PART_DES>
</DH675AU>
</dataroot>
Here is my desired output:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<entry>
<figure>99999</figure>
<description>DIPSTICK</description>
<description>O-RING</description>
<description>SCREW, SELF-TAPPING</description>
<note>NOTE: (1) NOT SERVICED SEPARATELY. INCLUDED IN</note>
<note>58F-98-40740 SEAL KIT.</note>
</entry>
<entry>
<figure>69500</figure>
<description>DIPSTICK</description>
<description>O-RING</description>
<description>SCREW, SELF-TAPPING</description>
</entry>
</root>
Here is my stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="3.0" expand-text="true">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/dataroot">
<root>
<xsl:call-template name="make-components"/>
</root>
</xsl:template>
<xsl:template name="make-components">
<xsl:for-each-group select="*" group-by="child::FIG_NO">
<xsl:call-template name="make-entries"/>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="make-entries">
<entry>
<figure><xsl:apply-templates
select="current-group()[1]/FIG_NO"/></figure>
<xsl:for-each select="current-group()">
<xsl:choose>
<xsl:when test="PART_DES[matches(.,'NOTE')] or
preceding::PART_DES[matches(.,'NOTE')]">
<note>
<xsl:apply-templates select="PART_DES"/>
</note>
</xsl:when>
<xsl:otherwise>
<description>
<xsl:apply-templates select="PART_DES"/>
</description>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</entry>
</xsl:template>
</xsl:stylesheet>
Here is what I am getting:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<entry>
<figure>99999</figure>
<description>DIPSTICK</description>
<description>O-RING</description>
<description>SCREW, SELF-TAPPING</description>
<note>NOTE: (1) NOT SERVICED SEPARATELY. INCLUDED IN</note>
<note>58F-98-40740 SEAL KIT.</note>
</entry>
<entry>
<figure>69500</figure>
<note>DIPSTICK</note>
<note>O-RING</note>
<note>SCREW, SELF-TAPPING</note>
</entry>
</root>
The idea is that when I see a "NOTE" string, I want that entry and all
following within the same group to be <note> elements. So I am look for
preceding-sibling or self that contains "NOTE" but restricted to the same
group. I am using XSLT 3. Thank you very much.
Rick
Rick Quatro
Carmen Publishing Inc.
585-729-6746
[email protected] <mailto:[email protected]>
http://www.frameexpert.com/store
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
<http://lists.mulberrytech.com/unsub/xsl-list/612310> EasyUnsubscribe (
<> by email)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--
------=_NextPart_000_044E_01D74D93.F2E40500
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sc=
hemas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/of=
fice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta ht=
tp-equiv=3DContent-Type content=3D"text/html; charset=3Dus-ascii"><meta nam=
e=3DGenerator content=3D"Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle21
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang=3DEN-US link=3D"#0563C1" vlink=3D"#954F72" sty=
le=3D'word-wrap:break-word'><div class=3DWordSection1><p class=3DMsoNormal>=
Here is my sample input:<o:p></o:p></p><p class=3DMsoNormal><o:p> </o:=
p></p><p class=3DMsoNormal><?xml version=3D"1.0" encoding=3D&q=
uot;UTF-8"?><o:p></o:p></p><p class=3DMsoNormal><dataroot><o:=
p></o:p></p><p class=3DMsoNormal> <DH675AU><o:p></o=
:p></p><p class=3DMsoNormal> <=
FIG_NO>99999</FIG_NO><o:p></o:p></p><p class=3DMsoNormal> &nb=
sp; <PART_DES>DIPSTICK</PART_DES>=
<o:p></o:p></p><p class=3DMsoNormal> </DH675AU><o:p=
></o:p></p><p class=3DMsoNormal> <DH675AU><o:p></o:=
p></p><p class=3DMsoNormal> <F=
IG_NO>99999</FIG_NO><o:p></o:p></p><p class=3DMsoNormal> &nbs=
p; <PART_DES>O-RING</PART_DES><o:=
p></o:p></p><p class=3DMsoNormal> </DH675AU><o:p></=
o:p></p><p class=3DMsoNormal> <DH675AU><o:p></o:p><=
/p><p class=3DMsoNormal> <FIG_=
NO>99999</FIG_NO><o:p></o:p></p><p class=3DMsoNormal> &=
nbsp; <PART_DES>SCREW, SELF-TAPPING</PART_=
DES><o:p></o:p></p><p class=3DMsoNormal> </DH675AU&=
gt;<o:p></o:p></p><p class=3DMsoNormal> <DH675AU><o=
:p></o:p></p><p class=3DMsoNormal>  =
; <FIG_NO>99999</FIG_NO><o:p></o:p></p><p class=3DMsoNormal>&nb=
sp; <PART_DES>NOTE: (1) NOT SERVI=
CED SEPARATELY. INCLUDED IN</PART_DES><o:p></o:p></p><p class=3DMsoNo=
rmal> </DH675AU><o:p></o:p></p><p class=3DMsoNormal=
> <DH675AU><o:p></o:p></p><p class=3DMsoNormal>&nbs=
p; <FIG_NO>99999</FIG_NO><o=
:p></o:p></p><p class=3DMsoNormal>  =
; <PART_DES>58F-98-40740 SEAL KIT.</PART_DES><o:p></o:p></p><p =
class=3DMsoNormal> </DH675AU><o:p></o:p></p><p clas=
s=3DMsoNormal> <DH675AU><o:p></o:p></p><p class=3DM=
soNormal> <FIG_NO>69500<=
/FIG_NO><o:p></o:p></p><p class=3DMsoNormal> &nbs=
p; <PART_DES>DIPSTICK</PART_DES><o:p></o:p></p><p c=
lass=3DMsoNormal> </DH675AU><o:p></o:p></p><p class=
=3DMsoNormal> <DH675AU><o:p></o:p></p><p class=3DMs=
oNormal> <FIG_NO>69500</=
FIG_NO><o:p></o:p></p><p class=3DMsoNormal>  =
; <PART_DES>O-RING</PART_DES><o:p></o:p></p><p clas=
s=3DMsoNormal> </DH675AU><o:p></o:p></p><p class=3D=
MsoNormal> <DH675AU><o:p></o:p></p><p class=3DMsoNo=
rmal> <FIG_NO>69500</FIG=
_NO><o:p></o:p></p><p class=3DMsoNormal> &n=
bsp; <PART_DES>SCREW, SELF-TAPPING</PART_DES><o:p></o:p><=
/p><p class=3DMsoNormal> </DH675AU><o:p></o:p></p><=
p class=3DMsoNormal></dataroot><o:p></o:p></p><p class=3DMsoNormal><o=
:p> </o:p></p><p class=3DMsoNormal>Here is my desired output:<o:p></o:=
p></p><p class=3DMsoNormal><o:p> </o:p></p><p class=3DMsoNormal><?x=
ml version=3D"1.0" encoding=3D"UTF-8"?><o:p></o:p></=
p><p class=3DMsoNormal><root><o:p></o:p></p><p class=3DMsoNormal>&nbs=
p; <entry><o:p></o:p></p><p class=3DMsoNormal>  =
; <figure>99999</figure><o:p></o:p></p><p class=3DM=
soNormal> <description>DIPSTICK</des=
cription><o:p></o:p></p><p class=3DMsoNormal> &nb=
sp; <description>O-RING</description><o:p></o:p></p><p class=3D=
MsoNormal> <description>SCREW, SELF-TAP=
PING</description><o:p></o:p></p><p class=3DMsoNormal> &nb=
sp; <note>NOTE: (1) NOT SERVICED SEPARATELY. INCLUDED IN&=
lt;/note><o:p></o:p></p><p class=3DMsoNormal> &nb=
sp; <note>58F-98-40740 SEAL KIT.</note><o:p></o:p></p><p class=
=3DMsoNormal> </entry><o:p></o:p></p><p class=3DMsoNormal=
> <entry><o:p></o:p></p><p class=3DMsoNormal> =
<figure>69500</figure><o:p></o:p></p><p clas=
s=3DMsoNormal> <description>DIPSTICK<=
;/description><o:p></o:p></p><p class=3DMsoNormal> &nbs=
p; <description>O-RING</description><o:p></o:p></p><p cla=
ss=3DMsoNormal> <description>SCREW, SEL=
F-TAPPING</description><o:p></o:p></p><p class=3DMsoNormal> &nbs=
p; </entry><o:p></o:p></p><p class=3DMsoNormal></root><o:p></o:=
p></p><p class=3DMsoNormal><o:p> </o:p></p><p class=3DMsoNormal>Here i=
s my stylesheet:<o:p></o:p></p><p class=3DMsoNormal><o:p> </o:p></p><p=
class=3DMsoNormal><?xml version=3D"1.0" encoding=3D"UTF-=
8"?><o:p></o:p></p><p class=3DMsoNormal><xsl:stylesheet xmlns:xs=
l=3D"http://www.w3.org/1999/XSL/Transform"<o:p></o:p></p><p class=
=3DMsoNormal> xmlns:xs=3D"http://www.w3.org/2001/XML=
Schema"<o:p></o:p></p><p class=3DMsoNormal> xmlns:ma=
th=3D"http://www.w3.org/2005/xpath-functions/math"<o:p></o:p></p>=
<p class=3DMsoNormal> exclude-result-prefixes=3D"xs =
math"<o:p></o:p></p><p class=3DMsoNormal> version=3D=
"3.0" expand-text=3D"true"><o:p></o:p></p><p class=
=3DMsoNormal> <o:p></o:p></p><p class=3DMsoNormal> &=
nbsp; <xsl:output method=3D"xml" indent=3D"yes=
"/><o:p></o:p></p><p class=3DMsoNormal> <o:p></o:=
p></p><p class=3DMsoNormal> <xsl:template match=
=3D"/dataroot"><o:p></o:p></p><p class=3DMsoNormal>  =
; <root><o:p></o:p></p><p class=3DMsoNo=
rmal> <=
;xsl:call-template name=3D"make-components"/><o:p></o:p></p><p=
class=3DMsoNormal> </root>=
<o:p></o:p></p><p class=3DMsoNormal> </xsl:template>=
;<o:p></o:p></p><p class=3DMsoNormal> <o:p></o:p></p><p c=
lass=3DMsoNormal> <xsl:template name=3D"make=
-components"><o:p></o:p></p><p class=3DMsoNormal> =
<xsl:for-each-group select=3D"*" grou=
p-by=3D"child::FIG_NO"><o:p></o:p></p><p class=3DMsoNormal>&nb=
sp; <xsl:cal=
l-template name=3D"make-entries"/><o:p></o:p></p><p class=3DMs=
oNormal> </xsl:for-each-group&=
gt;<o:p></o:p></p><p class=3DMsoNormal> </xsl:template=
><o:p></o:p></p><p class=3DMsoNormal> <o:p></o:p></p><=
p class=3DMsoNormal> <xsl:template name=3D"m=
ake-entries"><o:p></o:p></p><p class=3DMsoNormal> =
<entry><o:p></o:p></p><p class=3DMsoNormal>&=
nbsp; <figur=
e><xsl:apply-templates select=3D"current-group()[1]/FIG_NO"=
/></figure><o:p></o:p></p><p class=3DMsoNormal> &=
nbsp; <xsl:for-each select=3D&=
quot;current-group()"><o:p></o:p></p><p class=3DMsoNormal> &nb=
sp; =
<xsl:choose><o:p></o:p></p><p class=3DMsoNormal> &n=
bsp;  =
; <xsl:when test=3D"PART_DES[matches(.,'NOT=
E')] or preceding::PART_DES[matches(.,'NOTE')]"><o:p></o:p></p><p c=
lass=3DMsoNormal> &nbs=
p; &=
nbsp; <note><o:p></o:p></p><p class=3DMsoNormal> &nb=
sp; =
<xsl:=
apply-templates select=3D"PART_DES"/><o:p></o:p></p><p class=
=3DMsoNormal> &n=
bsp;  =
; </note><o:p></o:p></p><p class=3DMsoNormal> =
&nb=
sp; </xsl:when><o:p></o:p></p><p class=3DMsoNormal> =
&nb=
sp; <xsl:otherwise><o:p></o:p></p><p cl=
ass=3DMsoNormal>  =
; &n=
bsp; <description><o:p></o:p></p><p class=3DMsoNormal> &nb=
sp; =
&l=
t;xsl:apply-templates select=3D"PART_DES"/><o:p></o:p></p><p c=
lass=3DMsoNormal> &nbs=
p; &=
nbsp; </description><o:p></o:p></p><p class=3DMsoNormal> &=
nbsp; &nbs=
p; </xsl:otherwise><o:p></o:p></p><p class=3D=
MsoNormal>  =
; </xsl:choose><o:p></o:p></p><p class=3DMsoN=
ormal> &l=
t;/xsl:for-each><o:p></o:p></p><p class=3DMsoNormal> &n=
bsp; </entry><o:p></o:p></p><p class=3DMsoNormal>&n=
bsp; </xsl:template><o:p></o:p></p><p class=3DMsoNormal>&=
nbsp; <o:p></o:p></p><p class=3DMsoNormal></xsl:styles=
heet><o:p></o:p></p><p class=3DMsoNormal><o:p> </o:p></p><p class=
=3DMsoNormal>Here is what I am getting:<o:p></o:p></p><p class=3DMsoNormal>=
<o:p> </o:p></p><p class=3DMsoNormal><?xml version=3D"1.0"=
; encoding=3D"UTF-8"?><o:p></o:p></p><p class=3DMsoNormal><=
root><o:p></o:p></p><p class=3DMsoNormal> <entry><o:p>=
</o:p></p><p class=3DMsoNormal> <figure>=
;99999</figure><o:p></o:p></p><p class=3DMsoNormal> =
<description>DIPSTICK</description><o:p></o:p></p>=
<p class=3DMsoNormal> <description>O-RI=
NG</description><o:p></o:p></p><p class=3DMsoNormal>  =
; <description>SCREW, SELF-TAPPING</description><o:=
p></o:p></p><p class=3DMsoNormal> <note>=
;NOTE: (1) NOT SERVICED SEPARATELY. INCLUDED IN</note><o:p></o:p></p>=
<p class=3DMsoNormal> <note>58F-98-4074=
0 SEAL KIT.</note><o:p></o:p></p><p class=3DMsoNormal> &l=
t;/entry><o:p></o:p></p><p class=3DMsoNormal> <entry><=
o:p></o:p></p><p class=3DMsoNormal> <figur=
e>69500</figure><o:p></o:p></p><p class=3DMsoNormal> &n=
bsp; <note>DIPSTICK</note><o:p></o:p></p><p class=
=3DMsoNormal> <note>O-RING</note>=
<o:p></o:p></p><p class=3DMsoNormal> <note=
>SCREW, SELF-TAPPING</note><o:p></o:p></p><p class=3DMsoNormal>&nb=
sp; </entry><o:p></o:p></p><p class=3DMsoNormal></root><o=
:p></o:p></p><p class=3DMsoNormal><span lang=3Den-BB><o:p> </o:p></spa=
n></p><p class=3DMsoNormal>The idea is that when I see a “NOTE”=
string, I want that entry and all following within the same group to be &l=
t;note> elements. So I am look for preceding-sibling or self that contai=
ns “NOTE” but restricted to the same group. <span lang=3Den-BB>=
I am using XSLT 3. Thank you very much.<o:p></o:p></span></p><p class=3DMso=
Normal><span lang=3Den-BB><o:p> </o:p></span></p><p class=3DMsoNormal>=
<span lang=3Den-BB>Rick<o:p></o:p></span></p><p class=3DMsoNormal><o:p>&nbs=
p;</o:p></p><p class=3DMsoNormal>Rick Quatro<o:p></o:p></p><p class=3DMsoNo=
rmal>Carmen Publishing Inc.<o:p></o:p></p><p class=3DMsoNormal>585-729-6746=
<o:p></o:p></p><p class=3DMsoNormal><a href=3D"mailto:[email protected]"=
>[email protected]</a><o:p></o:p></p><p class=3DMsoNormal><a href=3D"htt=
p://www.frameexpert.com/store">http://www.frameexpert.com/store</a><o:p></o=
:p></p><p class=3DMsoNormal><o:p> </o:p></p><p class=3DMsoNormal><span=
lang=3Den-BB><o:p> </o:p></span></p><div><div style=3D'border:none;bo=
rder-top:solid black 1.0pt;padding:4.0pt 0in 0in 0in;margin-top:5.0pt;margi=
n-bottom:5.0pt'><p class=3DMsoNormal align=3Dcenter style=3D'text-align:cen=
ter;background:#DDDDDD'><span style=3D'font-size:7.5pt;font-family:"Arial",=
sans-serif;color:#888888'><a href=3D"http://www.mulberrytech.com/xsl/xsl-li=
st">XSL-List info and archive</a> <o:p></o:p></span></p><p class=3DMsoNorma=
l align=3Dcenter style=3D'text-align:center;background:#DDDDDD'><span style=
=3D'font-size:7.5pt;font-family:"Arial",sans-serif;color:#888888'><a href=
=3D"http://lists.mulberrytech.com/unsub/xsl-list/612310"><span style=3D'col=
or:blue'>EasyUnsubscribe</span></a> (<a href=3D""><span style=3D'color:blue=
'>by email</span></a>) <o:p></o:p></span></p></div></div></div></body></htm=
l>
<div><!-- begin bl.html.trailer -->
<div style=3D"border-top:1px solid black; background-color: #dddddd;
color: #888888; font-size: smaller; padding: 5px; text-align: center;
font-family: arial,verdana,arial,sans-serif; margin-top:1em; clear:
both; margin: auto">
<a href=3D"http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style=3D"text-align:center;">
<a style=3D"color: blue;"
href=3D"http://lists.mulberrytech.com/unsub/xsl-list/3329386"
>EasyUnsubscribe</a>
(<a style=3D"color: blue;"
href=3D"mailto:[email protected]?subject=3Dremove"
>by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>
------=_NextPart_000_044E_01D74D93.F2E40500--