xml - XSLT Can't match element with specific namespace -


i have xml source file:

<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="c:\iso19139_rve.xsl"?> <md_metadata xmlns="http://www.isotc211.org/schemas/2005/gmd" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:gco="http://www.isotc211.org/schemas/2005/gco" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemalocation="http://www.isotc211.org/schemas/2005/gmd/gmd.xsd">     <identificationinfo>         <md_dataidentification>                 <extent>                 <ex_extent>                     <geographicelement>                         <ex_geographicextent>                             <ex_geographicboundingbox>                                 <westboundlongitude>                                     <gco:decimal>1</gco:decimal>                                 </westboundlongitude>                                 <eastboundlongitude>                                     <gco:decimal>2</gco:decimal>                                 </eastboundlongitude>                                 <southboundlatitude>                                     <gco:decimal>3</gco:decimal>                                 </southboundlatitude>                                 <northboundlatitude>                                     <gco:decimal>4</gco:decimal>                                 </northboundlatitude>                             </ex_geographicboundingbox>                         </ex_geographicextent>                     </geographicelement>                     <temporalelement>                         <ex_temporalextent>                             <extent>                                 <gml:timeperiod gml:id="tp1">                                     <gml:begin>                                         <gml:timeistant gml:id="ti1">                                             <gml:timeposition>2007-12-01</gml:timeposition>                                         </gml:timeistant>                                     </gml:begin>                                     <gml:end>                                         <gml:timeistant gml:id="ti2">                                             <gml:timeposition>2010-01-01</gml:timeposition>                                         </gml:timeistant>                                     </gml:end>                                 </gml:timeperiod>                             </extent>                         </ex_temporalextent>                     </temporalelement>                 </ex_extent>             </extent>         </md_dataidentification>     </identificationinfo> </md_metadata> 

and need replace block simple one:

... <gml:timeperiod gml:id="tp1">     <gml:beginposition>2007-12-01</gml:beginposition>     <gml:endposition>2010-01-01</gml:endposition> </gml:timeperiod> ... 

this transformation:

<xsl:stylesheet     version="2.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform"     xmlns:xlink="http://www.w3.org/1999/xlink"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:gml="http://www.opengis.net/gml/3.2"     xmlns:gco="http://www.isotc211.org/schemas/2005/gco"     xmlns:gmd="http://www.isotc211.org/schemas/2005/gmd"     xmlns="http://www.isotc211.org/schemas/2005/gmd"     >      <xsl:strip-space elements="*"/>      <xsl:output indent="yes" encoding="utf-8"/>      <!-- identity template -->     <xsl:template match="node() | @*">         <xsl:copy>             <xsl:apply-templates select="node() | @*" />         </xsl:copy>     </xsl:template>      <xsl:template match="gml:timeperiod">         <xsl:copy>             <xsl:apply-templates select="@*"/>             <beginposition>                 <xsl:value-of select="gml:begin/gml:timeistant/gml:timeposition"/>             </beginposition>             <endposition>                 <xsl:value-of select="gml:end/gml:timeistant/gml:timeposition"/>             </endposition>         </xsl:copy>     </xsl:template> </xsl:stylesheet> 

there's xmlns:gml="http://www.opengis.net/gml" declaration on top of stylesheet think it's matter of namespace. if put break point near the

<xsl:template match="gml:timeperiod" exclude-result-prefixes="#all">

line, never enter inside code. seems if need go through <gmd:...> elements, works fine, when need reach <gml:...> (or other different gmd) element, doesn't match.

-- updated on 2014-04-15 --

i forgot specify need convert upper-case "tp1" attribute value of <gml:timeperiod gml:id="tp1"> element. need change on actual transformation?

as tomalak mentions in comments, root cause of problem have different namespace uris mapped gml prefix in input xml , in stylesheet, elements in xml , elements xslt looking match not considered same.

regarding addition:

i forgot specify need convert upper-case "tp1" attribute value of <gml:timeperiod gml:id="tp1"> element. need change on actual transformation?

this should matter of adding 1 template (once you've got namespaces aligned) , using xpath 2.0 upper-case function:

<xsl:template match="gml:timeperiod/@gml:id">   <xsl:attribute name="gml:id" select="upper-case(.)" /> </xsl:template> 

this affect ids of gml:timeperiod elements, if want upper-case all ids make match="@gml:id" instead.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -