Move the xsl:if to the end of the match="pd" template, then delete the
contents of the xsl:for-each and make it an xsl:apply-templates,
instead.
-Brandon :)
On Thu, Jan 6, 2011 at 9:45 AM, Jimenez, Luis <Luis.Jimenez@xxxxxxxxx> wrote:
> Hi,
>
> who can help me.
>
> how I can change the following XSLT output to include information that
identifies the field <cod> 012 </ cod> XML1 the file, but that in turn finish
processing the file in this part.
>
> The code 012 is not that I want to display. Is the data that comes within
the XML file that is identified with that code.
>
> ***********************
> My XSL File:
>
> <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> <xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>
> <xsl:strip-space elements="*"/>
>
> <xsl:variable name="from"><c>456</c></xsl:variable>
>
> <xsl:template match="/">
> <spoolpd>
> <xsl:for-each
select="(document('C:\XML1.TXT')|document('C:\XML2.TXT'))/spoolpd/pd[a/cab/co
d[.=document('')/*/xsl:variable[@name='from']/c]]">
> <xsl:copy>
> <xsl:copy-of select="@*"/>
> <xsl:copy-of select="a"/>
> </xsl:copy>
> <xsl:if test="not(a/cab/cod = '012')">
> <xsl:apply-templates select="following-sibling::pd[1]"/>
> </xsl:if>
> </xsl:for-each>
> </spoolpd>
> </xsl:template>
>
> <xsl:template match="pd">
>
> <xsl:copy>
> <xsl:copy-of select="@*"/>
> <xsl:copy-of select="a"/>
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
> ***********************
> My XML1 File:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <spoolpd>
> <pd use="x">
> <a>
> <cab>
> <cod>789</cod>
> <name>Luis</name>
> </cab>
> </a>
> </pd>
> <pd use="x">
> <a>
> <cab>
> <cod>456</cod>
> <name>Juan</name>
> </cab>
> </a>
> </pd>
> <pd use="y">
> <a>
> <cab>
> <cod>123</cod>
> <name>Jose</name>
> </cab>
> </a>
> </pd>
> <pd use="z">
> <a>
> <cab>
> <cod>012</cod>
> <name>Maria</name>
> </cab>
> </a>
> </pd>
> <pd use="h">
> <a>
> <cab>
> <cod>987</cod>
> <name>Valery</name>
> </cab>
> </a>
> </pd>
> </spoolpd>
>
> ***********************
> My XML2 File:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <spoolpd>
> <pd use="a">
> <a>
> <cab>
> <cod>012</cod>
> <name>James</name>
> </cab>
> </a>
> </pd>
> <pd use="b">
> <a>
> <cab>
> <cod>123</cod>
> <name>Antonio</name>
> </cab>
> </a>
> </pd>
> <pd use="c">
> <a>
> <cab>
> <cod>456</cod>
> <name>Mary</name>
> </cab>
> </a>
> </pd>
> <pd use="d">
> <a>
> <cab>
> <cod>789</cod>
> <name>Julieth</name>
> </cab>
> </a>
> </pd>
> </spoolpd>
>
> ***********************
> My current output:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <spoolpd>
> <pd use="x"> ==> XML1 File
> <a>
> <cab>
> <cod>456</cod>
> <name>Juan</name>
> </cab>
> </a>
> </pd>
> <pd use="y"> ==> XML1 File
> <a>
> <cab>
> <cod>123</cod>
> <name>Jose</name>
> </cab>
> </a>
> </pd>
> <pd use="c"> ==> XML2 File
> <a>
> <cab>
> <cod>456</cod>
> <name>Mary</name>
> </cab>
> </a>
> </pd>
> <pd use="d"> ==> XML2 File
> <a>
> <cab>
> <cod>789</cod>
> <name>Julieth</name>
> </cab>
> </a>
> </pd>
> </spoolpd>
>
> is missing the following, which should come out also in the output:
>
> <pd use="z">
> <a>
> <cab>
> <cod>012</cod>
> <name>Maria</name>
> </cab>
> </a>
> </pd>
>
> Thank for the help.
>
> Luis Fdo.
>
> -----Mensaje original-----
> De: Brandon Ibach [mailto:brandon.ibach@xxxxxxxxxxxxxxxxxxx]
> Enviado el: Miircoles, 05 de Enero de 2011 02:00 p.m.
> Para: xsl-list
> Asunto: Re: Capture Range of Documents
>
> I could review your XSLT to determine why it isn't working the way you
> want, but if the approach you're trying isn't working, perhaps you
> could try something else. I've already developed and tested a
> complete XSLT stylesheet that produces the output you indicated you
> wanted from the input you supplied. The relevant snippets of that
> stylesheet (two different versions, pick whichever one you like
> better) were included in my initial response.
>
> Have you tried the code I posted? Did it work? If not, what were the
> problems? Was there some other way in which this code was unsuitable
> for your needs, perhaps due to an additional requirement that I
> misunderstood or that you have not yet conveyed?
>
> -Brandon :)
>
>
> On Wed, Jan 5, 2011 at 12:54 PM, Jimenez, Luis <Luis.Jimenez@xxxxxxxxx>
wrote:
>> Hi Brandon,
>>
>> Annex the files for you to review.
>>
>> *************************
>> XML1 File:
>>
>> <?xml version="1.0" encoding="iso-8859-1"?>
>> <spoolpd>
>> <pd use="x">
>> <a>
>> <cab>
>> <cod>789</cod>
>> <name>Luis</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="x">
>> <a>
>> <cab>
>> <cod>456</cod>
>> <name>Juan</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="y">
>> <a>
>> <cab>
>> <cod>123</cod>
>> <name>Jose</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="z">
>> <a>
>> <cab>
>> <cod>012</cod>
>> <name>Maria</name>
>> </cab>
>> </a>
>> </pd>
>> </spoolpd>
>>
>> *************************
>> XML2 File:
>>
>> <?xml version="1.0" encoding="iso-8859-1"?>
>> <spoolpd>
>> <pd use="a">
>> <a>
>> <cab>
>> <cod>012</cod>
>> <name>James</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="b">
>> <a>
>> <cab>
>> <cod>123</cod>
>> <name>Antonio</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="c">
>> <a>
>> <cab>
>> <cod>456</cod>
>> <name>Mary</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="d">
>> <a>
>> <cab>
>> <cod>789</cod>
>> <name>Julieth</name>
>> </cab>
>> </a>
>> </pd>
>> </spoolpd>
>>
>> *************************
>> XSL 1.0 File:
>>
>> <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
>> <xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>
>> <xsl:strip-space elements="*"/>
>>
>> <xsl:variable name="from"><c>456</c></xsl:variable>
>> <xsl:variable name="until"><c>012</c></xsl:variable>
>>
>> <xsl:variable name="condicion1"
select="(document('C:\XML1.TXT'))/spoolpd/pd[a/cab/cod[.>=document('')/*/x
sl:variable[@name='from']/c]]"> </xsl:variable>
>> <xsl:variable name="condicion2"
select="(document('C:\XML2.TXT'))/spoolpd/pd[a/cab/cod[.>=document('')/*/x
sl:variable[@name='from']/c]]"> </xsl:variable>
>>
>> <xsl:template match="/">
>> <spoolpd>
>> <xsl:for-each select="$condicion1|$condicion2">
>> <xsl:copy>
>> <xsl:copy-of select="@*"/>
>> <xsl:copy-of select="a"/>
>> </xsl:copy>
>> </xsl:for-each>
>> </spoolpd>
>> </xsl:template>
>>
>> </xsl:stylesheet>
>>
>> *************************
>> The desired output is only from a position (from cod:456) in each of the
files to another position later (until cod: 012):
>>
>> <?xml version="1.0" encoding="iso-8859-1"?> <spoolpd> <pd use="x"> ==> XML1
File
>> <a>
>> <cab>
>> <cod>456</cod>
>> <name>Juan</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="y"> ==> XML1 File
>> <a>
>> <cab>
>> <cod>123</cod>
>> <name>Jose</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="z"> ==> XML1 File
>> <a>
>> <cab>
>> <cod>012</cod>
>> <name>Maria</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="c"> ==> XML2 File
>> <a>
>> <cab>
>> <cod>456</cod>
>> <name>Mary</name>
>> </cab>
>> </a>
>> </pd>
>> <pd use="d"> ==> XML2 File
>> <a>
>> <cab>
>> <cod>789</cod>
>> <name>Julieth</name>
>> </cab>
>> </a>
>> </pd>
>> </spoolpd>
>>
>> Thank for the help.
>>
>> Luis Fdo.
>>
>> -----Mensaje original-----
>> De: Brandon Ibach [mailto:brandon.ibach@xxxxxxxxxxxxxxxxxxx]
>> Enviado el: Miircoles, 05 de Enero de 2011 11:32 a.m.
>> Para: xsl-list
>> Asunto: Re: Capture Range of Documents
>>
>> I don't understand what you're asking for, here. You provided
>> examples of two input files and the desired output and I supplied code
>> that would produce that output from those inputs (provided appropriate
>> code around it to iterate over the two files and build the overall
>> document). Have your requirements changed? In what way?
>>
>> -Brandon :)
>>
>>
>> On Wed, Jan 5, 2011 at 10:06 AM, Jimenez, Luis <Luis.Jimenez@xxxxxxxxx>
wrote:
>>> Hi Brandon,
>>>
>>> I have the following xsl, but this only captures if the value is greater
or less than, and therefore can capture the first <pd> is not needed, so I
have not been able to do is capture from one position (<pd>) to another
determined position (<pd>).
>>>
>>> I appreciate the help you can give me.
>>>
>>> *****************************+
>>> My XSL:
>>>
>>> <?xml version="1.0" encoding="ISO-8859-1"?>
>>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
>>> <xsl:output method="xml" version="1.0" encoding="iso-8859-1"
indent="yes"/>
>>> <xsl:strip-space elements="*"/> <!-- Quita Los Espacios en Blanco de cada
Elemento -->
>>>
>>> <xsl:variable name="from"><c>456</c></xsl:variable>
>>> <xsl:variable name="until"><c>012</c></xsl:variable>
>>>
>>> <xsl:variable name="condicion1" select="(document('C:\
PRUEBAS.TXT'))/spoolpd/pd[a/cab/cod[.>=document('')/*/xsl:variable[@name='
from']/c] and a/cab/cod[.<=document('')/*/xsl:variable[@name='until']/c]]">
</xsl:variable>
>>>
>>> <xsl:template match="/">
>>> <spoolpd>
>>> <xsl:for-each select="$condicion1">
>>> <xsl:copy>
>>> <xsl:copy-of select="@*"/>
>>> <xsl:copy-of select="a"/>
>>> </xsl:copy>
>>> </xsl:for-each>
>>> </spoolpd>
>>> </xsl:template>
>>>
>>> </xsl:stylesheet>
>>>
>>>
>>> Thanks,
>>>
>>> Luis Fdo.
>>>
>>> -----Mensaje original-----
>>> De: Brandon Ibach [mailto:brandon.ibach@xxxxxxxxxxxxxxxxxxx]
>>> Enviado el: Miircoles, 05 de Enero de 2011 05:41 a.m.
>>> Para: xsl-list
>>> Asunto: Re: Capture Range of Documents
>>>
>>> There seem to be two questions, here. First, how to process more than
>>> one file and merge the results together. I'll skip the details on
>>> that since I'm sure it's been covered here many times and the solution
>>> really depends on how you generate your list of files, which you
>>> didn't specify.
>>>
>>> The more interesting question is how to grab a range of sibling nodes
>>> starting with the first one which matches a certain criterion and
>>> ending with the first one after that which matches another criterion.
>>> One solution (assuming your code to loop through your files does an
>>> xsl:apply-templates on each file's document element):
>>>
>>> <xsl:template match="spoolpd">
>>> <xsl:variable name="start" select="pd[a/cab/cod =
'456'][1]"/>
>>> <xsl:variable name="range" select="$start |
>>> $start/following-sibling::pd[count(following-sibling::pd[a/cab/cod =
>>> '012']) = count($start/following-sibling::pd[a/cab/cod = '012'])] |
>>> $start/following-sibling::pd[a/cab/cod = '012'][1]"/>
>>> <xsl:copy-of select="$range"/>
>>> </xsl:template>
>>>
>>> Even simpler (relying less on XPath and more on XSLT):
>>>
>>> <xsl:template match="spoolpd">
>>> <xsl:apply-templates select="pd[a/cab/cod = '456'][1]"/>
>>> </xsl:template>
>>>
>>> <xsl:template match="pd">
>>> <xsl:copy-of select="."/>
>>> <xsl:if test="not(a/cab/cod = '012')">
>>> <xsl:apply-templates
select="following-sibling::pd[1]"/>
>>> </xsl:if>
>>> </xsl:template>
>>>
>>> -Brandon :)
>>>
>>>
>>> On Tue, Jan 4, 2011 at 9:11 PM, Jimenez, Luis <Luis.Jimenez@xxxxxxxxx>
wrote:
>>>> Hi All,
>>>>
>>>> Happy New Year.
>>>>
>>>> I am working with XSLT 1.0.
>>>>
>>>> As I can capture with a XSL in several XML files ranging from documents
according to their locations within the file, for example:
>>>>
>>>> Capturing all the documents from the code: 456, until the code: 012
>>>>
>>>> ******************
>>>> My XML1 File:
>>>>
>>>> <?xml version="1.0" encoding="iso-8859-1"?>
>>>> <spoolpd>
>>>> <pd use="x">
>>>> <a>
>>>> <cab>
>>>> <cod>789</cod>
>>>> <name>Luis</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="x">
>>>> <a>
>>>> <cab>
>>>> <cod>456</cod>
>>>> <name>Juan</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="y">
>>>> <a>
>>>> <cab>
>>>> <cod>123</cod>
>>>> <name>Jose</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="z">
>>>> <a>
>>>> <cab>
>>>> <cod>012</cod>
>>>> <name>Maria</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> </spoolpd>
>>>>
>>>> ******************
>>>> My XML2 File:
>>>>
>>>> <?xml version="1.0" encoding="iso-8859-1"?>
>>>> <spoolpd>
>>>> <pd use="a">
>>>> <a>
>>>> <cab>
>>>> <cod>012</cod>
>>>> <name>James</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="b">
>>>> <a>
>>>> <cab>
>>>> <cod>123</cod>
>>>> <name>Antonio</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="c">
>>>> <a>
>>>> <cab>
>>>> <cod>456</cod>
>>>> <name>Mary</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="d">
>>>> <a>
>>>> <cab>
>>>> <cod>789</cod>
>>>> <name>Julieth</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> </spoolpd>
>>>>
>>>> ******************
>>>> My output desired:
>>>>
>>>> <?xml version="1.0" encoding="iso-8859-1"?>
>>>> <spoolpd>
>>>> <pd use="x"> ==> capturing the first xml file (XML1)
>>>> <a>
>>>> <cab>
>>>> <cod>456</cod>
>>>> <name>Juan</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="y"> ==> capturing the first xml file (XML1)
>>>> <a>
>>>> <cab>
>>>> <cod>123</cod>
>>>> <name>Jose</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="z"> ==> capturing the first xml file (XML1)
>>>> <a>
>>>> <cab>
>>>> <cod>012</cod>
>>>> <name>Maria</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="c"> ==> capturing the second xml file (XML2)
>>>> <a>
>>>> <cab>
>>>> <cod>456</cod>
>>>> <name>Mary</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> <pd use="d"> ==> capturing the second xml file (XML2)
>>>> <a>
>>>> <cab>
>>>> <cod>789</cod>
>>>> <name>Julieth</name>
>>>> </cab>
>>>> </a>
>>>> </pd>
>>>> </spoolpd>
>>>>
>>>> thank you very much for the help.
>>>>
>>>> Luis Fdo.
|