tesmc
asked on
error when calling apply templates when node contains attributes
I have an xml where a node may or may not include attributes.
<A>
<Envelope>
<Body>
<TravelRS EchoToken="String" TimeStamp="2013-04-29T19:0 2:31" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<TravelItinerary> ... </TravelItinerary>
</Body>
</Envelope>
</A>
My xsl does an apply-template to loop through the TravelRS. However, if there are attributes included it does not go through into the code. How can I work around that?
This is what my xsl has
<xsl:when test="Envelope/Body/Travel RS">
<xsl:apply-templates select="Envelope/Body/Trav elRS"/>
</xsl:when>
<A>
<Envelope>
<Body>
<TravelRS EchoToken="String" TimeStamp="2013-04-29T19:0
<TravelItinerary> ... </TravelItinerary>
</Body>
</Envelope>
</A>
My xsl does an apply-template to loop through the TravelRS. However, if there are attributes included it does not go through into the code. How can I work around that?
This is what my xsl has
<xsl:when test="Envelope/Body/Travel
<xsl:apply-templates select="Envelope/Body/Trav
</xsl:when>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
u were right, it was namespaces. i added code to remove these before my xsl is executed. thanks.
I am not sure about what you say...
but this line
xmlns="http://webservices..com/XML/2001/08"
puts all elements in a default namespace.
and will break te stylesheet snippet you just showed us
xmlns:xs="http://www.w3.org/2001/XMLSchema"
does not hurt unless you have a xs:prefixed-element
Can you post the entire stylesheet and an example element
Do you need the stylesheet to work for both with and without the namespaces?
If that is the case, use one of the following approaches
- use XSLT2 and put a *: in front of each element in each XPath
- make two passes, one to get rid of the namespaces in any case and then the stylesheet you already have. If this approach makes sense, I will make the first stylesheet for you
If it only needs to work in case of namespace declarations... you can hardwire the namespace as I did with the ns1:
but this line
xmlns="http://webservices..com/XML/2001/08"
puts all elements in a default namespace.
and will break te stylesheet snippet you just showed us
xmlns:xs="http://www.w3.org/2001/XMLSchema"
does not hurt unless you have a xs:prefixed-element
Can you post the entire stylesheet and an example element
Do you need the stylesheet to work for both with and without the namespaces?
If that is the case, use one of the following approaches
- use XSLT2 and put a *: in front of each element in each XPath
- make two passes, one to get rid of the namespaces in any case and then the stylesheet you already have. If this approach makes sense, I will make the first stylesheet for you
If it only needs to work in case of namespace declarations... you can hardwire the namespace as I did with the ns1:
missed your comment prior to my last comment
anyway, you are welcome
anyway, you are welcome
ASKER
I didn't realize, but it's not the attributes that is causing the apply-templates to be skipped, but instead it's the xmlns:xs="http://www.w3.org/2001/XMLSchema" line which causes failure.
If i remove this line then success.
I have it as follows:
<TravelRS EchoToken="String" TimeStamp="2013-04-29T19:0
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
How can i call my template while maintaining those 3 xmlns prefixes?