xml - XSLT sort order to match order of different parent node -


i have 2 nodes incidentally share subset of data. need sort first set based on original order of second.

to give example, consider following sets of points , lines. every "start" , "end" point each line in every case listed in points list.

<points>     <point name="point1">0 0</point>     <point name="point2">0 1</point>     <point name="point3">1 1</point>     <point name="point4">1 0</point> </points>  <shape>     <line name="line1">         <start>0 0</start>         <end>0 1</end>     </line>     <line name="line2">         <start>0 1</start>         <end>1 1</end>     </line>     <line name="line3">         <start>1 1</start>         <end>1 0</end>     </line>     <line name="line4">         <start>1 0</start>         <end>0 0</end>     </line> </shape> 

i need sort points values match same order end points listed shape.

for above example, expected xslt output follows...

point2 0 1 point3 1 1 point4 1 0 point1 0 0 

to specific, i'm working cogo points , alignment objects autocad, trying customize reports based on landxml outputs civil3d. sample above give me direction. appreciated.

i think should work: template matches end nodes , grabs point node same text value (there's second template matching text() make sure doesn't outputted unintentionally):

<?xml version="1.0" encoding="utf-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">     <xsl:output method="text" omit-xml-declaration="yes" encoding="utf-8" indent="yes" />      <xsl:template match="/root/shape/line/end">         <xsl:variable name="endpttext" select="./text()" />         <xsl:value-of select="/root/points/point[text() = $endpttext]/@name" /><xsl:text> </xsl:text><xsl:value-of select="$endpttext"/> <xsl:text> </xsl:text>     </xsl:template>      <xsl:template match="text()" /> </xsl:transform> 

produces:

point2 0 1 point3 1 1 point4 1 0 point1 0 0 

from:

<root>   <points>     <point name="point1">0 0</point>     <point name="point2">0 1</point>     <point name="point3">1 1</point>     <point name="point4">1 0</point>   </points>    <shape>     <line name="line1">         <start>0 0</start>         <end>0 1</end>     </line>     <line name="line2">         <start>0 1</start>         <end>1 1</end>     </line>     <line name="line3">         <start>1 1</start>         <end>1 0</end>     </line>     <line name="line4">         <start>1 0</start>         <end>0 0</end>     </line>   </shape> </root>         

xsltransform

just note if have 2 identical point text nodes won't work, , if don't have point node corresponding end node won't work.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -