Re: ALMOST WORKING was Re: [xsl] XSLT to populate a SAML AttributeStatement from an XML

Subject: Re: ALMOST WORKING was Re: [xsl] XSLT to populate a SAML AttributeStatement from an XML
From: "ohaya ohaya@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 19 Jan 2023 23:34:37 -0000
 Hi,

FYI, the XSLT I posted was just a snippet of the whole XSLT that I needed to
make. There were bunch of other template matches that I needed, because there
were like 14 or 15, but they were all under /record/adrRecord, but not
directly under /record/adrRecord, i.e., there were some under:

/record/adrRecord
/record/adrRecord/personnel
/record/adrRecord/enterpriseUser
etc.

That was why the apply-templates had select "/record/adrRecord/*", i.e, I
wanted all of the template matches "under" "/record/adrRecord".

If I had made the apply-templates on line 9 specific to a single path,
wouldn't the entire XSLT have only processed that one template?

Thanks,
Jim


     On Thursday, January 19, 2023, 12:22:47 PM EST, Bauman, Syd
s.bauman@xxxxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

 #yiv2831365257 P {margin-top:0;margin-bottom:0;}While the bgatewayb
platform on which you are running the XSLT may well have 2.0 capability, the
stylesheet itself says it is 1.0. My system, at least, will not allow me to
use a 2.0 function (tokenize()) in a 1.0 stylesheet.
But after converting the "1.0" to "2.0" I tried running, and indeed the
b1111111b and burn:NORM:V01b are in the output.
Here is the stylesheet (refactored a wee bit) with line numbers:01| B <?xml
version="1.0" encoding="UTF-8"?>02| B <xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"03| B 
B xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"04| B 
B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"05| B 
B xmlns:xsd="http://www.w3.org/2001/XMLSchema"; >06| B 07| B  B <xsl:template
match="/">08| B  B  B <saml:AttributeStatement>09| B  B  B 
B <xsl:apply-templates select="/record/adrRecord/*"/>10| B  B 
B </saml:AttributeStatement>11| B  B </xsl:template>12| B 13| B 
B <xsl:template match="/record/adrRecord/personnel/ADM_ORG_CD">14| B  B 
B <saml:Attribute Name="MY_ORG_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">15| B  B  B 
B <xsl:for-each select="tokenize(., ':')">16| B  B  B  B 
B <saml:AttributeValue xsi:type="xsd:string">17| B  B  B  B  B 
B <xsl:value-of select="."/>18| B  B  B  B  B </saml:AttributeValue>19| B  B 
B  B </xsl:for-each>20| B  B  B </saml:Attribute>21| B  B </xsl:template>22|
B 23| B </xsl:stylesheet>
Line 09 asks that all element children of /record/adrRecord be processed. What
it means (roughly speaking) to bprocessb an element is for the XSLT engine
to reach into the input tree and pick up each matching construct (in this case
the element children of/record/adrRecord, in document order), and for each one
ask the question bis there a template that matches this?b. If the answer
is byesb, run that template on this construct (in this case an element).
If the answer is bnob, run the build-in template on this element.
The elements that are picked up to process are <PN_ID>, and <personnel>. For
neither is there a matching template. (The only template other than bmatch
rootb matches/record/adrRecord/personnel/ADM_ORG_CD.) So in both cases, the
built-in template is run. The built-in template for elements says, basically,
bprocess my childrenb.
So the next step is for the XSLT engine to process the <PN_ID> with the
bprocess my childrenb built-in template. In this case, the one child is a
7-charcter long text node. That node is grabbed, and the XSLT engine asks the
question bis there a template that matches this?b. The answer is bnob,
so the engine hands the node over to the built-in template. The built-in
template for text nodes says (basically) bput this in the outputb. Thus
the output has the string b1111111b.
Roughly the same thing occurs with
/record/adrRecord/personnel/ADM_ORG_CD/DOD_ASSOC_CD. (No template, so the
built-in template is run instead.)
Seems to me (without thinking about it much) that this problem stems from the
mis-match between the @select on line 09 and the @match on line 13. Probably
reasonable to be specific on the @select
(/record/adrRecord/personnel/ADM_ORG_CD); also would be more readable if the
@match just matched the element (ADM_ORG_CD), although that might cause
problems iff there are other<ADM_ORG_CD> elements that you do not want to
match (and other code thatmight match them).
HTH.

I tried the XSLT on the gateway, which does have XSLT 2.0. It looks like it
worked, but it's generating some "EXTRANEOUS" output... specifically,
it looks like is outputting the VALUE of some the other elements, I am not
sure why :(...

1-Here's the source XML:

<record>
<adrRecord>
<PN_ID>1111111</PN_ID>
<personnel>
<ADM_ORG_CD>urn:NORM:DEPT</ADM_ORG_CD>
<DOD_ASSOC_CD>urn:NORM:V01</DOD_ASSOC_CD>
</personnel>
</adrRecord>
</record>




2-Here's the XSLT:

<xsl:stylesheet version="1.0"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:template match="/">
<saml:AttributeStatement>
<xsl:apply-templates select="/record/adrRecord/*"/>
</saml:AttributeStatement>
</xsl:template>

<xsl:template match="/record/adrRecord/personnel/ADM_ORG_CD">
<saml:Attribute Name="MY_ORG_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">

<xsl:for-each select="tokenize(.,':')">
<saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"><xsl:value-of select="."/></saml:AttributeValue>
</xsl:for-each>
</saml:Attribute>
</xsl:template>


<!--
<xsl:template match="/record/adrRecord/personnel/ADM_ORG_CD">
<saml:Attribute Name="MY_ORG_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"> <xsl:value-of
select="/record/adrRecord/personnel/ADM_ORG_CD" />
</saml:AttributeValue>
</saml:Attribute>
</xsl:template>

<xsl:template match="/record/adrRecord/personnel/DOD_ASSOC_CD">
<saml:Attribute Name="MY_ASSOC_CD"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
<saml:AttributeValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string"> <xsl:value-of
select="/record/adrRecord/personnel/DOD_ASSOC_CD" />
</saml:AttributeValue>
</saml:Attribute>

</xsl:template>
-->

</xsl:stylesheet>



3-Here's the output when I run the XSLT:

<?xml version="1.0" encoding="UTF-8"?><saml:AttributeStatement
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>1111111<saml:Attribute
Name="MY_PN_ID"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"><saml:Attribut
eValue xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string">urn</saml:AttributeValue><saml:AttributeValue
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string">NORM</saml:AttributeValue><saml:AttributeValue
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xsi:type="xsd:string">DEPT</saml:AttributeValue></saml:Attribute>urn:NORM:V01
</saml:AttributeStatement>



NOTICE that it is outputting the "
1111111" and the "urn:NORM:V01".

Why is that?XSL-List info and archiveEasyUnsubscribe(by email)

Current Thread