I have this xml file:
<A9-ArchaeologicalExcavation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<E53-Place>
<Name>asdad</Name>
<District/>
<Parish/>
<Gps>
<Latitude/>
<Longitude/>
</Gps>
<A2-StratigraphicVolumeUnit>
<Timeline/>
<Description/>
<Gps>
<Latitude/>
<Longitude/>
</Gps>
<S19-EncounterEvent>
<Date>2001-11-12</Date>
<E24-PhysicalManThing Inventory_number="1">
<E36-VisualItem/>
<Order_number>Triangular</Order_number>
<Group>
<Group-name>Reta</Group-name>
<Sub_type>true</Sub_type>
</Group>
<E3-ConditionState>
<E55-Type/>
</E3-ConditionState>
<E55-Type>Alongado</E55-Type>
<Variant>Espessa</Variant>
<Typometry Unit="mm">
<Lenght>23</Lenght>
<Width>12</Width>
<Thickness>5</Thickness>
<Body_lenght>19</Body_lenght>
<Base_lenght>4</Base_lenght>
</Typometry>
<Morphology>
<Point>true</Point>
<Body>false</Body>
<Base>Triangular</Base>
</Morphology>
<Retouch>
<Location/>
<Mode/>
<Amplitude/>
<Direction/>
<Delineation/>
<Orientation/>
<Shape/>
</Retouch>
<Raw_material/>
<Observations/>
</E24-PhysicalManThing>
</S19-EncounterEvent>
</A2-StratigraphicVolumeUnit>
</E53-Place>
</A9-ArchaeologicalExcavation>
I have a web page where i want to search for a certain items that match, lets say variant = 'Espessa' and return all the @Inventory_number. I use GET to pass the values inserted in my html form and then i want to create an Xquery code that recieves the values, passes those values into the XSLT code and returns an html file with the items found.
So far i have this in my Xquery:
xquery version "3.0" encoding "UTF-8";
declare variable $fi as xs:integer :=5;
declare variable $fi2 as xs:string := "variant";
let $fi:= request:get-parameter("termo", 5)
let $fi2 :=request:get-parameter("elementos", "variant")
let $x := doc("/db/apps/MegaLOD/arrowheads/arrowheads.xml")
let $filter := concat($fi2, " = ", $fi, "")
for $arrowheads in $x/arrowheads
let $arrowhead_list :=
(for $arrowhead in $arrowheads/arrowhead[$filter]
return $arrowhead)
return
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Arrowheads</h2>
<xsl:for-each select="A9-ArchaeologicalExcavation/E53-Place/A2-StratigraphicVolumeUnit/S19-EncounterEvent/E24-PhysicalManThing[Variant = 'Espessa']">
<p><xsl:value-of select="@Inventory_number"/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I decided first to try with fixed values, Variant = 'Espessa', but the query returns an empty page.
I want to use the variables $fi and $fi2 in my XSLT code.
What is wrong in my code?
How can I use $fi and $fi2 variables in the xslt code?
you need to actually evaluate the XSLT from XQuery, that can be done by calling the
transform#1function - see: https://www.w3.org/TR/xpath-functions-31/#func-transform. There are several options for passing in parameters to XSLT from XQuery, but I will include just one such option here where I usexsl:param.You also have some problems in your
$filterpredicate. I am afraid that XML is not composed ofkey=valuepairs, instead it is a tree and, so the predicate needs to query the correct node in the tree.I have made a few assumptions about what you are trying to achieve, but hopefully this will serve as a good example for you. Feel free to ask any further questions...