简体   繁体   中英

XSLT code to get the value of an attribute of the last element

I am XSLT beginner and have an XML with the connections tags as mentioned below ..

This is my XML:

<connections sourceElement="/3/@elements.2" targetElement="/3/@elements.0" schemaName="Target_Query"/> 
<connections sourceElement="/3/@elements.1" targetElement="/3/@elements.3" schemaName="R3_DF_PRODUCT"/> 
<connections sourceElement="/3/@elements.3" targetElement="/3/@elements.2" schemaName="Transform3"/>

And I want to iterate through the connections and get only the last one

//dataflow:DataFlow/connections 

(which @targetElement isn't used as @SourceElement in other <connections> ).
I need to get the value of @schemaName .

Can any body help with the sample snippets to achieve this?

To get the schemaName attribute of the last connections element, you can use the following XPath-1.0 expression:

//dataflow:DataFlow/connections[last()]/@schemaName

IN XSLT it can be accessed with

<xsl:value-of select="//dataflow:DataFlow/connections[last()]/@schemaName"/>

Output is:

Transform3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM