Count the number of nested child nodes - xslt-1.0

I want to find the number of RegisterValueData elements inside the below structure for all the NewConsumptionData and RegisterConsumptionData elements, so a single figure.
<ConsumptionData>
<NewConsumptionData>
<FromDate>2021-02-02T00:00:00</FromDate>
<RegistersValues>
<RegisterConsumptionData>
<Timeframe>TOTAL_HOUR</Timeframe>
<Values>
<RegisterValueData>
<Quality>NONVALIDATED</Quality>
</RegisterValueData>
<RegisterValueData>
<Quality>VALIDATED</Quality>
</RegisterValueData>
</Values>
</RegisterConsumptionData>
<RegisterConsumptionData>
<Timeframe>TOTAL_HOUR</Timeframe>
<Values>
<RegisterValueData>
<Quality>NONVALIDATED</Quality>
</RegisterValueData>
<RegisterValueData>
<Quality>VALIDATED</Quality>
</RegisterValueData>
</Values>
</RegisterConsumptionData>
</RegistersValues>
</NewConsumptionData>
<NewConsumptionData>
<FromDate>2021-02-02T00:00:00</FromDate>
<RegistersValues>
<RegisterConsumptionData>
<Timeframe>TOTAL_HOUR</Timeframe>
<Values>
<RegisterValueData>
<Quality>NONVALIDATED</Quality>
</RegisterValueData>
<RegisterValueData>
<Quality>VALIDATED</Quality>
</RegisterValueData>
</Values>
</RegisterConsumptionData>
<RegisterConsumptionData>
<Timeframe>TOTAL_HOUR</Timeframe>
<Values>
<RegisterValueData>
<Quality>NONVALIDATED</Quality>
</RegisterValueData>
<RegisterValueData>
<Quality>VALIDATED</Quality>
</RegisterValueData>
</Values>
</RegisterConsumptionData>
</RegistersValues>
</NewConsumptionData>
What seems simple I cannot get my head around this. I am trying a recursive function (If that's the right way) but not sure how to set up the parameters and prevent it looping indefinitely.

You can easily use the count() function to count child or descendant nodes:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<result>
<xsl:value-of select="count(//RegisterValueData)" />
</result>
</xsl:template>
</xsl:stylesheet>
or a little more efficiently:
<xsl:template match="/ConsumptionData">
<result>
<xsl:value-of select="count(NewConsumptionData/RegistersValues/RegisterConsumptionData/Values/RegisterValueData)" />
</result>
</xsl:template>
Result
<?xml version="1.0" encoding="UTF-8"?>
<result>8</result>

Related

Using XSLT to visit child nodes and retrieve element values

Using the following input XML, my goal is to initially select portfolios/portfolio node, then the <tradeContribution> child nodes - specifically contributions/tradeContribution .
These tradeContribution nodes will then be transformed into the <trade> nodes in the xml output shown below.
My xml output and XSLT code follows below...
<outBound>
<requestReceivedTime>2014-05-15 15:20:42.279</requestReceivedTime>
<responseSentTime>2014-05-15 15:20:42.338</responseSentTime>
<body>
<portfolios>
<portfolio id="36" nodeDate="2014-05-06">
<query>
<firstTerm>
<date>2014-05-06</date>
</firstTerm>
<lastTerm>
<date>2014-05-06</date>
</lastTerm>
</query>
<exposure>492691.50878619519</exposure>
<contributions>
<tradeContribution contextId="0" contribution="267624.242492124" dealId="IRSW-TRADE-00011" desc="IRSW-FIX-FLOAT" order="0" sysId="1" tradeId="IRSW-TRADE-00011">
<hideTrade>false</hideTrade>
<readOnly>false</readOnly>
</tradeContribution>
<tradeContribution contextId="7" contribution="225067.26629407122" dealId="IRSW-TRADE-00020" desc="IRSW-FIX-FLOAT" order="1" sysId="2" tradeId="IRSW-TRADE-00020">
<hideTrade>false</hideTrade>
<readOnly>false</readOnly>
</tradeContribution>
</contributions>
<nodeAnalysis id="HSVaR 5D 100 ES">
<method>INTERPOLATED_EXPECTED_SHORTFALL</method>
<exposure>true</exposure>
<percentile>100</percentile>
</nodeAnalysis>
</portfolio>
</portfolios>
</body>
</outBound>
My desired XML output is:
<?xml version="1.0" ?>
<collection>
<trade>
<legal_id>36</legal_id>
<tradeRef>IRS-RRT-002</tradeRef>
<system>MY SYSTEM IRS</system>
<indepMtmValuation>111111</indepMtmValuation>
<indepMtmValuationCcy>USD</indepMtmValuationCcy>
<principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
<principalDealLevelAmount>14</principalDealLevelAmount>
<principalDealLevelCurrency>USD</principalDealLevelCurrency>
<principalDealLevelType>Independent Amount</principalDealLevelType>
<operation>U</operation>
</trade>
<trade>
<legal_id>36</legal_id>
<system>MY SYSTEM CDS</system>
<tradeRef>CDS-RRT-008</tradeRef>
<mtmValuation>222222</mtmValuation>
<mtmValuationDate>2013-09-11</mtmValuationDate>
<mtmValuationLocalSysCcy>USD</mtmValuationLocalSysCcy>
<counterpartyDealLevelUpfront>TRUE</counterpartyDealLevelUpfront>
<counterpartyDealLevelAmount>15</counterpartyDealLevelAmount>
<counterpartyDealLevelCurrency>JPY</counterpartyDealLevelCurrency>
<counterpartyDealLevelType>Independent Amount</counterpartyDealLevelType>
</trade>
</collection>
The XSLT I have so far is as follows; however, I have a problem:
1) Trying to find the best way to pull the value of attribute "id", which is part of <portfolio id="36" nodeDate="2014-05-06"> .
I need to output it to <legal_id>, but this here is NOT working:
<legal_id><xsl:value-of select="../portfolio[#id]"/></legal_id>
Your advice would be greatly appreciate in helping to properly construct my XSLT to produce the desired XML output shown above:
My XSLT code thus far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="1.0">
<!-- Variable declaration -->
<xsl:variable name="hsVar1D" select="'1D (99%)'"></xsl:variable>
<xsl:variable name="hsVar5D" select="'HSVaR 5D 100 ES'"></xsl:variable>
<xsl:template match="/*">
<collection>
<xsl:apply-templates select="/outbound/body/portfolios/portfolio[descendant::nodeAnalysis[#id[contains(.,$hsVar5D)]]]" />
</collection>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates select="contributions/tradeContribution"/>
</xsl:template>
<xsl:template match="contributions/tradeContribution">
<trade>
<!-- QUESTION: For <legal_id> what is the best way to select the #id attrib from the ancestor node <portfolio> -->
<legal_id><xsl:value-of select="#id"/></legal_id>
<legal_id222><xsl:value-of select="../portfolio[#id]"/></legal_id222>
<tradeRef>IRS-RRT-002</tradeRef>
<system>MY SYSTEM IRS</system>
<indepMtmValuation>111111</indepMtmValuation>
<indepMtmValuationCcy>USD</indepMtmValuationCcy>
<principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
<principalDealLevelAmount><xsl:value-of select="exposure"></xsl:value-of></principalDealLevelAmount>
<principalDealLevelCurrency>USD</principalDealLevelCurrency>
<principalDealLevelType>Independent Amount</principalDealLevelType>
<operation>U</operation>
</trade>
</xsl:template>
Try it this way:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- Variable declaration -->
<xsl:variable name="hsVar1D" select="'1D (99%)'"></xsl:variable>
<xsl:variable name="hsVar5D" select="'HSVaR 5D 100 ES'"></xsl:variable>
<xsl:template match="/">
<collection>
<xsl:apply-templates select="outBound/body/portfolios/portfolio[nodeAnalysis[contains(#id,$hsVar5D)]]/contributions/tradeContribution" />
</collection>
</xsl:template>
<xsl:template match="tradeContribution">
<trade>
<legal_id>
<xsl:value-of select="../../../portfolio/#id"/>
</legal_id>
<tradeRef>IRS-RRT-002</tradeRef>
<system>RAZOR IRS</system>
<indepMtmValuation>111111</indepMtmValuation>
<indepMtmValuationCcy>USD</indepMtmValuationCcy>
<principalDealLevelUpfront>TRUE</principalDealLevelUpfront>
<principalDealLevelAmount>
<xsl:value-of select="../../nodeAnalysis/exposure"/>
</principalDealLevelAmount>
<principalDealLevelCurrency>USD</principalDealLevelCurrency>
<principalDealLevelType>Independent Amount</principalDealLevelType>
<operation>U</operation>
</trade>
</xsl:template>
</xsl:stylesheet>
--
Note outBound vs. razorOutbound

XProc: XD0001 It is a dynamic error if a non-XML resource is produced on a step output or arrives on a step input

Requirement: Is to add correct Doctype declaration on the output xml [The root element of the input xml can be chapter or section element]
Input XML: chapter.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd">
<chapter>
<title>Chapter Template Title</title>
<para>Text</para>
<section>
<title>Section Title</title>
<para>Section text</para>
</section>
</chapter>
XSLT file: test.xsl:
Stylesheet just copies input xml to output and adds #sec on all
element
Stylesheet adds correct doctype declaration to output xml, because
the input xml root element can be <chapter> or
<section> element
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="add-doctype-declaration">
<xsl:choose>
<xsl:when test="/chapter">
<xsl:text disable-output-escaping="yes">
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd">
</xsl:text>
</xsl:when>
<xsl:when test="/section">
<xsl:text disable-output-escaping="yes">
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd">
</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="add-doctype-declaration"/>
<xsl:apply-templates/>
</xsl:template>
<!-- Identity Template -->
<xsl:template match="#*|*|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="section">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<xsl:attribute name="sec">
<xsl:number/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Expected output.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "docbookx.dtd">
<chapter>
<title>Chapter Template Title</title>
<para>Text</para>
<section sec="1">
<title>Section Title</title>
<para>Section text</para>
</section>
</chapter>
Using any XSLT engine, the transformation works absolutely fine, and able to get the expected output
But, if the transformation is done through XProc I end up with the following error. Can someone help in resolving this error
err:XD0001 : XD0001 It is a dynamic error if a non-XML resource is
produced on a step output or arrives on a step input.
XProc file: test.xpl
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" name="testing">
<p:input port="source">
<p:document href="chapter.xml"/>
</p:input>
<p:output port="result">
<p:empty/>
</p:output>
<p:xslt version="1.0" name="transform">
<p:input port="stylesheet">
<p:document href="test.xsl"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:store omit-xml-declaration="false" encoding="utf-8" name="serialize">
<p:with-option name="href" select="output.xml"/>
</p:store>
</p:declare-step>
Here is two simple examples that shows that you don't need to contextualize the Doctype generation
Section
http://www.sharexml.com/x/get?k=uWn0KA7RThnt
Chapter http://www.sharexml.com/x/get?k=wAJlbUJfzIYQ
Hope this helps
[UPDATED AFTER ANSWER]
And if you want that doctype change dynamically
Section http://www.sharexml.com/x/get?k=pBAwCds86RnQ
Chapter http://www.sharexml.com/x/get?k=JHEWghzgWIq1
Hope this helps
What goes wrong here is that the doctype you are creating here, is passed as part of the result of the XSLT step to the XProc engine. However, it is passed as character data outside the root element. XProc does not allow this.
There are actually two issues with approach:
Don't use disable-output-escaping unless you can't do anything else. The xsl:output instruction has perfect means to create the doctype you want, just add a public-doctype and system-doctype attribute to it.
output options of the XSLT will be ignored, as the result isn't actually being serialized by the XSLT engine, but by XPRoc. So you will have to put those doctype attribute on the p:store step, to make it work within XProc.
HTH!

Xslt to copy inner xml without unused namespaces

I wish to remove a couple of unused namespaces from a resulting output from an xslt stylesheet.
The xml to feed in is a wrapper around another xml message which is seen in the BodyMessage element. An example of the entire xml can bee seen below:
<?xml version="1.0" encoding="utf-8"?>
<ns0:Wrapper xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0" xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0">
<TaskName>SomeTaskName</TaskName>
<TaskStatus>Start</TaskStatus>
<Id>Y/0070/0010</Id>
<BodyMessage>
<tva:TVAMain rightsOwner="FAIRY" xmlns:tva="urn:tva:metadata:2004">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
</tva:TVAMain>
</BodyMessage>
</ns0:Wrapper>
When I try to extract the xml out of the BodyMessage element I get unused namespaces returned
xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0"
xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0"
These are not required but I do not understand how to remove them within my xslt.
Please note I DO want to keep
xmlns:tva="urn:tva:metadata:2004"
The stylesheet I used is:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tva="urn:tva:metadata:2004"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output encoding="UTF-8" method="xml" omit-xml-declaration="no" version="1.0" />
<xsl:template match="/">
<xsl:variable name="completeTva" select="//tva:TVAMain" />
<xsl:copy-of select ="$completeTva"/>
</xsl:template>
The output of the stylesheet is:
<?xml version="1.0" encoding="utf-8"?>
<tva:TVAMain rightsOwner="FAIRY" xmlns:tva="urn:tva:metadata:2004" xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0" xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
What I require is:
<?xml version="1.0" encoding="utf-8"?>
<tva:TVAMain rightsOwner="FAIRY" xmlns:tva="urn:tva:metadata:2004">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
Any help would be greatly appreciated.
:)
This transformation (Sorry, this is a bug in the SO code-formatter!):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tva="urn:tva:metadata:2004"
xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0"
xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vtoDiscard" select=
"document('')
/*/namespace::*[name()='ns0' or name()='mco']"/>
<xsl:template match="tva:*">
<xsl:element name="{name()}"
namespace="urn:tva:metadata:2004">
<xsl:copy-of select="namespace::*[not(. = $vtoDiscard)]"/>
<xsl:copy-of select="#*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="text()[not(ancestor::BodyMessage)]"/>
</xsl:stylesheet>
when applied on the provided XML document:
<ns0:Wrapper
xmlns:ns0="http://ref.fairyliquidplc.ads/Schema/Fairy/Wrapper/1.0"
xmlns:mco="http://ref.fairyliquidplc.ads/Schema/Fairy/Common/1.0">
<TaskName>SomeTaskName</TaskName>
<TaskStatus>Start</TaskStatus>
<Id>Y/0070/0010</Id>
<BodyMessage>
<tva:TVAMain rightsOwner="FAIRY"
xmlns:tva="urn:tva:metadata:2004">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
</tva:TVAMain>
</BodyMessage>
</ns0:Wrapper>
produces the wanted, correct result:
<tva:TVAMain xmlns:tva="urn:tva:metadata:2004" rightsOwner="FAIRY">
<tva:Colour>red</tva:Colour>
<tva:Size>12</tva:Size>
<tva:Style>Skinny</tva:Style>
<tva:Fabric>Denim</tva:Fabric>
</tva:TVAMain>
Explanation:
Both xsl:copy and xsl:copy-of copy an element together with the namespace nodes that belong to it.
The way to strip some namespace nodes off an element is to re-create it using the xsl:element, then to copy from the original element only the wanted namespace nodes.

using bing api xslt

I'm trying to use the Bing Image api, but can't manage to get it working.
I'm trying to transform the result, but the transformation does not return anything useful.
I think this is because I'm doing something wrong with the namespaces, as it is something I find terribly confusing in all xml related languages...
here is an example of what I receive from Bing:
<?xml version="1.0" encoding="utf-8" ?>
<?pageview_candidate?>
<SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.2">
<Query>
<SearchTerms>natalie portman</SearchTerms>
</Query>
<mms:Image xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<mms:Total>644000</mms:Total>
<mms:Offset>0</mms:Offset>
<mms:Results>
<mms:ImageResult>
<mms:Title>Natalie Portman/natalie-portman-83</mms:Title>
<mms:MediaUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.jpg</mms:MediaUrl>
<mms:Url>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:Url><mms:DisplayUrl>http://www.bestidol.pl/natalieportman/slides/natalie-portman-83.php</mms:DisplayUrl>
<mms:Width>1024</mms:Width>
<mms:Height>768</mms:Height>
<mms:FileSize>95173</mms:FileSize>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Thumbnail>
<mms:Url>http://ts1.mm.bing.net/images/thumbnail.aspx?q=809383506038& amp;id=b829ae4c6df8866b6a07325bedca4bbd</mms:Url>
<mms:ContentType>image/jpeg</mms:ContentType>
<mms:Width>160</mms:Width>
<mms:Height>120</mms:Height>
<mms:FileSize>3838</mms:FileSize>
</mms:Thumbnail></mms:ImageResult>
<mms:ImageResult>
... other ImageResults and closing tags.
here my curent xslt transformation:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<xsl:template match="/">
<list>
<xsl:for-each select="//mms:ImageResult" >
<element>
<image>
<url><xsl:value-of select="/mms:MediaUrl" /></url>
<width><xsl:value-of select="/mms:Width" /></width>
<height><xsl:value-of select="/mms:Height" /></height>
</image>
</element>
</xsl:for-each>
</list>
</xsl:template>
</xsl:stylesheet>
does somebody see my mistake(s)?
because this transform returns me:
<list xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
<element>
<image>
<url/>
<width/>
<height/>
</image>
</element>
...
</list>
Shoudnt be...
<url><xsl:value-of select="mms:MediaUrl" /></url>
<width><xsl:value-of select="mms:Width" /></width>
<height><xsl:value-of select="mms:Height" /></height>
?

XPath when a root node and element have different Name Space attributes

I got struck with a problem in VB.Net getting Xpath for an XML element as shown below:
<Parent xmlns:"http://www.sample.com">
<body>
<Child xmlns:"http://www.notsample.com">
<element type="xyz"> ghghghghghg </element>
</Child>
</body>
</Parent>
I need Xpath of the "element" in above XML using VB.Net NameSpace Manager
For the "body" node i have done and its working but i couldnt do the same to "element":
dim bodynode as XMLNode=XML.SelectSingleNode(//ns:body,nsmngr)
where "nsmngr" is the namespacemanger created by me and "ns" is the name space of the "parent node" (which the "body" node inherits) added to the namespace manager as "ns"
Thanks
Kiran
There are two different ways to construct the needed XPath expression:
Define a second namespace binding with NamespaceManager, say ns2: bound to http://www.notsample.com. Then use:
/*/ns:body/ns2:Child/ns2:element
Don't use namespaces at all:
/*/*[name()='body']/*[name()='Child']/*[name()='element']
Given the following xml:
<OuterElem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:test="http://www.w3.org/2001/XMLSchema-instance1" xmlns:test1="http://www.w3.org/2001/XMLSchema-instance1">
<test:parent>
<test1:child1>blabla1</test1:child1>
<test1:child2>blabla2</test1:child2>
<test:child2>blabla3</test:child2>
</test:parent>
<test1:child1>blabla4</test1:child1>
</OuterElem>
the following xslt (xslt 1.0) copies all nodes except "test:parent/test1:child1":
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="http://www.w3.org/2001/XMLSchema-instance1" xmlns:test1="http://www.w3.org/2001/XMLSchema-instance1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="test:parent/test1:child1"/>
</xsl:stylesheet>
The result will be:
<OuterElem xmlns:test="http://www.w3.org/2001/XMLSchema-instance1" xmlns:test1="http://www.w3.org/2001/XMLSchema-instance1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test:parent>
<test1:child2>blabla2</test1:child2>
<test:child2>blabla3</test:child2>
</test:parent>
<test1:child1>blabla4</test1:child1>
</OuterElem>