how can i set up my xslt correctly? I hope you can help me.
If there are differents at "PackingslipId"-"LineItem"-"Lines" i don´t like to have "PackingslipId" and "DeliveryDate" on "HeaderInformation".
If the "PackingslipId" is always the same at "LineItem"-"Lines" than on "HeaderInformation" the output "PackingslipId" and "DeliveryDate" is ok.
Please note: (I don´t no if important; it also can be, that there is just one Article ("LineItem"-"Lines" - with "OrderLineNum" 1) - in this case, the "PackingslipId" is the same of "Lines" and "HeaderInformation" so "PackingslipId" and "DeliveryDate" should
be also on "HeaderInformation" and "LineItem"
You could use the template below. Expression lines[not(PackingslipId = preceding-sibling::lines/PackingslipId)] will get the lines whose PackingslipId is not the same as other,
if the count is one , it means they are all the same.
<xsl:template match="/salesinvoices/lineItem">
<xsl:choose>
<xsl:when test="
count(lines[not(PackingslipId = preceding-sibling::lines/PackingslipId)]) = 1
">
<xsl:copy-of select="//header/PackingslipId"/>
<xsl:copy-of select="//header/DeliveryDate"/>
</xsl:when>
<xsl:otherwise>
<empty>no data</empty> <!--it will be clear that you they are not the same ,you could remove it in your xslt-->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Do you mean you have successfully solved your problems through this way?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
3 Points
11 Posts
XSLT 1.0 output a value if condition
Nov 16, 2018 06:48 AM|juls_pro_37|LINK
Hi,
how can i set up my xslt correctly? I hope you can help me.
If there are differents at "PackingslipId"-"LineItem"-"Lines" i don´t like to have "PackingslipId" and "DeliveryDate" on "HeaderInformation".
If the "PackingslipId" is always the same at "LineItem"-"Lines" than on "HeaderInformation" the output "PackingslipId" and "DeliveryDate" is ok.
Please note: (I don´t no if important; it also can be, that there is just one Article ("LineItem"-"Lines" - with "OrderLineNum" 1) - in this case, the "PackingslipId" is the same of "Lines" and "HeaderInformation" so "PackingslipId" and "DeliveryDate" should be also on "HeaderInformation" and "LineItem"
My XML:
So in my case above, the output should be no "PackingsslipId" and "DeliveryDate" on "HeaderInformation":
Do you need more examples?
Thanks, Julian
Contributor
3500 Points
1300 Posts
Re: XSLT 1.0 output a value if condition
Nov 19, 2018 03:26 AM|Ackerly Xu|LINK
Hi juls_pro_37,
You could use the template below. Expression lines[not(PackingslipId = preceding-sibling::lines/PackingslipId)] will get the lines whose PackingslipId is not the same as other,
if the count is one , it means they are all the same.
Below is my test xml
The result.
You could also refer to the link below
https://stackoverflow.com/questions/3188749/xslt-how-to-check-if-certain-nodes-are-all-equal-in-one-parent
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
3 Points
11 Posts
Re: XSLT 1.0 output a value if condition
Nov 19, 2018 07:21 AM|juls_pro_37|LINK
Hi Ackerly Xu,
thanks for your input, but i think your xslt doesn´t work correctly. :( (Theres no correct output)
I show you, can you help me please?
My xslt (with your code - i changed header to HeaderInformation at copy)
My xml:
Thanks, best regards
Julian
Member
3 Points
11 Posts
Re: XSLT 1.0 output a value if condition
Nov 19, 2018 01:35 PM|juls_pro_37|LINK
thats it:
<div class="post-text" itemprop="text"> </div> <div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy"> <div class="grid--cell mr16">thx for your help!</div> <div class="grid--cell mr16"></div> <div class="grid--cell mr16">best regards</div> <div class="grid--cell mr16">Julian</div> </div>Contributor
3500 Points
1300 Posts
Re: XSLT 1.0 output a value if condition
Nov 20, 2018 02:01 AM|Ackerly Xu|LINK
Hi juls_pro_37,
Do you mean you have successfully solved your problems through this way?
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
3 Points
11 Posts
Re: XSLT 1.0 output a value if condition
Nov 20, 2018 08:49 AM|juls_pro_37|LINK
yes, thats the solution.